Context Provider in Layout Component for nested routes in a solid start App is undefined
I have a nested route routes/user/[id]
under routes/ folder, I have created a user.tsx file with following code.
As per expectation the component is acting as a layout for routes/user/[id], but when I try to access the
context using useContext(AppContext), the context is undefined.
4 Replies
Try this
const ctx = useContext(AppContext)
useContext does not provide a tuple. And if you destructure the context you’ll loose reactivity.
sorry it was
but yeah it doesn't work even if i don't de-structure.
The issue started appearing once I lifted the context provider up into the layout component.
If I move the context provider into the childRoute component, it works fine for other nested children
seems like the layout component is rendered on server side, I put some console.log into it and seeing them printed on the terminal.(VS Code)
is
C
coming from children
?
children
is a memo that will eagerly evaluate its contents, so the children will be produced before being wrapped in ProjectContext
that fixed it, thanks.