when I get data from another store in one store, it is not the latest data #1921
-
I have two stores
When I use the
|
Beta Was this translation helpful? Give feedback.
Answered by
dbritto-dev
Jul 7, 2023
Replies: 1 comment 3 replies
-
@Ali-ovo why not get them directly from const useStore = create<Store>()(
devtools((set) => ({
count: 0,
getInputValue: () => useInputStore.getState().inputValue, // form input store
setInputValue: (inputValue) => useInputStore.getState().setInputValue(inputValue), // form input store
increment: () => set((state) => ({ count: state.count + 1 })),
decrement: () => set((state) => ({ count: state.count - 1 })),
})),
); then you can use them like this: const Card = () => {
const getInputValue = useStore((storeState) => storeState.getInputValue);
const inputValue = getInputValue()
return (
<div>
<h3>inputValue: {inputValue}</h3> // It will never be updated here
</div>
);
}; |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah, that's expected because
getState
is not reactive. If you want the latest you should get it fromuseInputStore
if you want to split your store in multiple states you can useslices pattern