Trying to combine two stores #1854
-
Hello, import { create } from 'zustand'
import { temporal } from 'zundo'
const createSelectionStore = create((set) => ({
selected: [], // selected path indexes
select: (index) =>
...
deselect: () =>
...
}))
const createBikePathStore = create((set) => ({
paths: [],
visible: false,
setPaths: (paths) =>
...
setVisible: (visible) =>
...
}))
const useBikePathStore = create((set) => ({
...createSelectionStore(set),
...createBikePathStore(set),
}))
export default useBikePathStore I get this error. I first thought I had an issue with Zundo, but as you can see I'm not using the Could someone help me with that? I'm probably missing something so I posted this in general. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
@FlorianGoussin what you are looking for is the slices pattern https://docs.pmnd.rs/zustand/guides/slices-pattern The solution const createSelectionStore = (set) => ({ ... })
const createBikePathStore = (set) => ({ ... })
|
Beta Was this translation helpful? Give feedback.
-
I knew I was missing something. It makes sense that |
Beta Was this translation helpful? Give feedback.
-
What about if you have two slices with the same property or method names? I'm trying to separate the bound store like this:
I'm struggling to change the state, however, I was able to get the state with no issues. |
Beta Was this translation helpful? Give feedback.
@FlorianGoussin what you are looking for is the slices pattern https://docs.pmnd.rs/zustand/guides/slices-pattern
The solution