mandev7724
mandev7724
SSolidJS
Created by mandev7724 on 9/7/2024 in #support
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.
<ProjectContext.Provider value={{ state, setState }}>
<Toolbar />
<main class="flex flex-row text-center mx-auto text-gray-700 h-[90vh] w-full">
{C()}
</main>
</ProjectContext.Provider>


//child route
const [state, setState] = useContext(AppContext) as AppContextType;
<ProjectContext.Provider value={{ state, setState }}>
<Toolbar />
<main class="flex flex-row text-center mx-auto text-gray-700 h-[90vh] w-full">
{C()}
</main>
</ProjectContext.Provider>


//child route
const [state, setState] = useContext(AppContext) as AppContextType;
8 replies