howdy there folks. have a question for you regardi...
# support-questions-legacy
d
howdy there folks. have a question for you regarding the useSessionContext in React for SuperTokens. I am using TanStack Query to handle my various data fetching needs in my application. I have an API endpoint called user_info which is reachable at the endpoint
/me/
which provides various information about the current users session. And instead of passing the userId down the component tree, it would be much easier if I could just read the userId inside my useQuery call.
Copy code
export const useGetUserInfo = ({config}: UseUserInfoOptions) => {
  let userId = getUserId()
  
  return useQuery<ExtractFnReturnType<QueryFnType>>({
    ...config,
    queryKey: ['userInfo', userId],
    queryFn: () => getUserInfo(),
    enabled: !!userId
  });
};
I am pretty new to working with React so what I'm trying to figure out is, do I need to make this function and the components that depends on it async in order for this to work properly?
r
hey!
You don't need to make things async. Just use our useSessionContext hook in your component and read the user ID from the resulting session object.
d
thanks for the quick response as always @rp_st
yeah i think im just trying to over optimize a bit
now that ive drank the JS koolaid lol
i moved back to just passing in the user ID
r
Why do you need to pass the user id to the backend? Just use the session tokens
d
yeah i just realized that there really isnt a need to use userId as a query key at all
smh
r
Yup
d
well that cleans up my code nicely. ive been up for 24 hours on a marathon coding session so clearly my brain no worky so good 😄
after hitting my head on the desk daily the skies are finally parting and my app is coming together.
2 Views