Add more detailed explanation to the doc, about use of React's Context API under <Outlet /> descendants #9855
plumbdataio
started this conversation in
Proposals
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I tried to use
createContext/useContext
to pass context from parent to a descendant which was under multiple<Outlet />
nests, but it didn't work anduseContext()
only gave meundefined
value.Now I understand what I needed to do was either:
context
prop (ex. doing<Outlet context={useOutletContext()}>
in the multiple Outlets in the middle)UNSAFE_RemixContext
instead ofcreateContext()
's return valuebut both of which was not intuitive to me because, I need to relay contexts although React's context API should be there to avoid "relaying" props, or I need to use utility class with
UNSAFE_
prefix (and I have no idea why and how it's "unsafe"...).The real problem is that there is no documentation or issues which cleary mention that '
useContext()
will return undefined if you're trying to pass context to the descendant under the '.So my sugestion here is adding it to the document, somewhere like in this page.
It must be helpful as I thing there might be folks like me who wandered on the internet because of this...
*Please collect me if something above is wrong and my research was not enough
Thanks,
Beta Was this translation helpful? Give feedback.
All reactions