Slices patterns, access multiple slices: data cannot be accessed #2045
-
SummaryUsing your multiple slices pattern, I tried to add a slice which acts on other slices, as in your docs: Link to reproductionhttps://codesandbox.io/s/silly-tamas-2rp6gx?file=/src/store/index.ts Reset works, but Calc sum always displays 0. Check ListPlease do not ask questions in issues.
Please include a minimal reproduction.
Please check this if you're filing an issue regarding TypeScript.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Can anyone help here? |
Beta Was this translation helpful? Give feedback.
-
@norama you are trying to create actions base on create slice functions which is wrong, that's why you always get the default values. You should always use Here you go const createResetAllSlice = (set, get) => ({
resetAll: () => {
get().resetApples();
get().resetPears();
},
sum: () => get().apples + get().pears
}); |
Beta Was this translation helpful? Give feedback.
@norama you are trying to create actions base on create slice functions which is wrong, that's why you always get the default values. You should always use
get()
to access to any function or prop/field.Here you go