https://kotlinlang.org logo
#react
Title
# react
h

Hildebrandt Tobias

12/04/2023, 11:14 AM
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

turansky

12/06/2023, 11:36 PM
Do you have
QueryClient
inside loader context?
h

Hildebrandt Tobias

12/08/2023, 8:55 PM
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

turansky

12/08/2023, 10:13 PM
h

Hildebrandt Tobias

12/08/2023, 10:33 PM
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

turansky

12/08/2023, 11:09 PM
Do you want set context?
Or get context data inside loader?
h

Hildebrandt Tobias

12/09/2023, 2:34 PM
I only want to read the context data inside the loader.
t

turansky

12/09/2023, 3:27 PM
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

Hildebrandt Tobias

12/09/2023, 10:25 PM
Thanks, I'll play around a bit.
3 Views