-
Hi, I'm trying to combine a Zustand store with SWR. I wish to dispatch a Zustand action through Minimal repro codesandbox: https://codesandbox.io/s/lucid-pasteur-fin3w I used to do this with a Redux dispatch which worked fine, but now when refactoring to Zustand it does not seem to be possible anymore. Here's the code:
Help is greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Does defining the dispatcher above SWRConfiguration work for you? like const showLoading = useDisplayState(state => state.activateLoader)
export const SWRGlobalConfig = {
onLoadingSlow: () => { showLoading(); },
// ... You cannot use hooks inside those callbacks since they're just callbaks triggered on state change, which is outside of react render scope. |
Beta Was this translation helpful? Give feedback.
-
As an additional answer to this, I found out
|
Beta Was this translation helpful? Give feedback.
Does defining the dispatcher above SWRConfiguration work for you? like
You cannot use hooks inside those callbacks since they're just callbaks triggered on state change, which is outside of react render scope.