Skip to content

Clarification: Should the APIProvider be able to provide context to immediate children only or to all nested children? #420

Answered by hjdjoo
hjdjoo asked this question in Q&A
Discussion options

You must be logged in to vote

While creating an example in CodeSandbox, I saw what went wrong in my application -- the APIProvider is indeed functioning just fine as a regular context provider, and nested components are indeed able to read from the APIProviderContext as expected.

My issue came from nested routes, not components. If a component redirects the user to a route which renders a new page, the Provider Context is lost, as expected, since the parent components containing the context were unmounted, thus returning a null object.

I appreciate the response - thank you!

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@hjdjoo
Comment options

Answer selected by usefulthink
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants