My setup is as following. I have a layout component where I add a navigation component and children. I wrap them with my Provider like this
AppLayout.js
<Layout>
<Navigation/>
<main>
{children}
</main>
</Layout>
Now the <Navigation/> component has access to the data returned by React.useContext(ContextProvider).
However a child component of Layout does not! If I try to console.log(state) in the <Navigation/> component I get back the actual data as expected.
But when I have a child component like this:
Child.js
<AppLayout>
<div>Some content</div>
</AppLayout>
The state is always undefined. The only way I managed to solve this issue was by wrapping the Provider around the Component in the _app.js file. Does anyone know how to solve this without wrapping the provider around the <Component/> from _app.js file?