Hi y'all, my root.tsx contains a header with a profile link. In it, I want to I conditionally display things based on the session info like this
const mainPageLoaderData =
useRouteLoaderData<MainPageLoader>('pages/MainPage')
let isAuthenticated = mainPageLoaderData?.isAuthenticated
// ...conditional rendering
My MainPage.tsx loader looks like this
export let loader = async ({ context }: LoaderFunctionArgs) => {
// ... fetch user from database
return json({
isAuthenticated,
currentUser,
})
}
}
When I go to a different route, the pages/MainPage loader doesn't run. How do you pipe session info to different places (like my layour in root.tsx) without fetching the user 50 times for each loader?