Replies: 1 comment 2 replies
-
What I do is create a useCurrentUser hook which calls useQuery and made a request to an API endpoint where I could get the currently logged in user, if you use cookies to store your user auth token it will be a simple GET request, if you store your token somewhere else (e.g. localStorage) you can read it inside your query function and then send it to the API. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I keep hearing about React Query could replace server data on Redux/React Context. For example, say I have a Context (or Redux) that holds the current user information. I use this 'currentUser' object to show/hide various UI features based on their roles. So anywhere I need the 'currentUser', I simply write something like below code
const { currentUser } = useContext(AppContext);
If I use React Query for that purpose, how would I achieve that? In advance, thanks for your time for answering my question. This is the only question that's holding me back from using this awesome library!
Beta Was this translation helpful? Give feedback.
All reactions