Infinite Rerender with Custom Hook #2721
Unanswered
fazlulShanto
asked this question in
General
Replies: 1 comment 4 replies
-
@fazlulShanto would you mind creating a minimal repro on stackblitz? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I used
rematch.js
before in a pattern where i created 2/3models
. if i need states/actions from multiple model i usually create a new custom hook for that particular feature and share them from that single custom hook.i have tried same pattern with zustand but my component keeps calling the action i used inside a useEffect hook. it's a simple todo app which calls the fetch todo data action on initial render and then update the state.
CodeSandbox url : https://codesandbox.io/p/devbox/clever-neumann-24ndct
Here what i was doing?
useTodo
is the custom hook where i have imported all the things i need from zustand store & exported them. i might need data from multiple zustand store.useTodo
custom hook also have a useEffect which calls thefetchUserTodoList
only one time and thefetchUserTodoList
action fetch the data and update the zustand store state .i don't understand why i the useEffect keeps running infinitely here.
How can i fix this?
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions