How to get state data just after setting it #1414
-
I have a use case in my nextjs, which reads like this: I have this setup:
And this function that is called on auth success to set the data
To protect routes in the application I have this high order component
So in this component I check if the user data are present in the state, if not I want not to allow access to the route. The issue I have is that after the authentication, the check keeps returning me back to login as if the data were not present in the store. How can I solve this ? Seems there is a delay between setting the state and the data availability in the app. How to go around this please ? Thanks for any help |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can read the store value directly in a callback. |
Beta Was this translation helpful? Give feedback.
You can read the store value directly in a callback.
useAuthStore.getState().authUser
That said, deriving the global state to a local state seems like a bad practice. You should avoid the useState there.