In my project, I have a loader in the root.tsx file and a component called 'Nav' which utilizes the loader data using the useRouteLoaderData
hook. For instance,
const data = useRouteLoaderData('root')
as needed.
<body>
<Nav/>
<Layout>{children}</Layout>
<ScrollRestoration />
<Scripts />
<LiveReload />
</body>
The 'Nav' component is placed in the root because it should be present in all routes, including the error page.
My challenge lies in using the loader data within the 'Nav' component without encountering undefined values. So far, I have attempted using a DefaultErrorBoundary in root.tsx to catch errors, but I still face the issue of the data being undefined within the 'Nav' component.
This is how my root loader function is structured:
export async function loader() {
return defer(
{
navGraphql: await fetchGraphQL(navQuery),
ENV: {
STRAPI_URL: process.env.STRAPI_URL,
},
},
{
headers: { 'Cache-Control': 'public, s-maxage=300' },
}
)
}
If you want to take a look at how I've implemented the DefaultErrorBoundary, you can check out the repository here.
I'm currently trying to figure out why the loader data is undefined at the parent level and how I can resolve this issue. Has the approach changed in my remix version? Any suggestions or insights would be greatly appreciated.