useLoaderData returns null at first on client #11461
-
I have a page nested within a layout, they look like this:
Both have // auth.tsx
export const loader = async ({ request }: LoaderFunctionArgs) => {
return 'bar';
};
export default function Layout() {
const foo = useLoaderData<typeof loader>();
return <Outlet />
}
// _auth.login._index.tsx
export const loader = async ({ request }: LoaderFunctionArgs) => {
return 'abc';
};
export default function Page() {
// Returns null on first client render
const xyz = useLoaderData<typeof loader>();
return ...
} I'm finding that when I call SSR doesn't have this problem, if you stick a If I'm running the dev server and update a page, triggering HMR, My understanding is that |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Argh, I was misreading my own logs. It was the parent I think this makes sense...? Because the layout is a separate route...? So its loader doesn't get called...maybe...? I'm confused which loaders get called when. Wouldn't a layout's loader be called whenever its children are loaded, too? Is it bad practice to put a loader in a layout? |
Beta Was this translation helpful? Give feedback.
-
I'm not sure what I did exactly, but the problem seems to have gone away after I did some edits to |
Beta Was this translation helpful? Give feedback.
I'm not sure what I did exactly, but the problem seems to have gone away after I did some edits to
root.tsx
and did a hard refresh/clear cache on my browser.