In Strict Mode components are rendered twice to fi...
# react
h
In Strict Mode components are rendered twice to find unwanted behaviour. So how would you go about ensuring correct behaviour in this case? For example I want to fetch something from a backend API or OAuth, the way I understand it you want to fetch this kind of data in react loaders and not inside the component (render), but those loaders don't have access to
useContext
. So do I need to apply the way described here: https://stackoverflow.com/questions/74757787/react-data-router-pass-context-to-loader or is there a simpler way that I don't see for this overall issue?
t
Do you have
QueryClient
inside loader context?
h
I haven't used
QueryClient
at all yet. I am still trying to learn react and kotlin-react. Do you have any pointers what best to google or a good tutorial/article?
t
h
Thank you!
Hmm okay, that is just another lib to manage states. But in the React Router example I see that I can pass the context when I create the
browserRouter
. I wonder if this also works with the react built in
createContext()
. My question was more aimed at how to even get the context into the loaders and have them reference the correct context.
t
Do you want set context?
Or get context data inside loader?
h
I only want to read the context data inside the loader.
t
For now looks like
QueryClient
in loader context (loader parameter) is what will cover your needs
Or you can construct your custom loader context, but it won't be very flexible
h
Thanks, I'll play around a bit.