Skip to content

Any way to access the server data from a client loader? #12862

Closed Answered by gustavopch
davidbielik asked this question in Q&A
Discussion options

You must be logged in to vote

That's because serverData is usually the name you give to the return of serverLoader, as in:

export const clientLoader = async ({ serverLoader }: Route.ClientLoaderArgs) => {
  const serverData = await serverLoader()
  return serverData
}

See: https://reactrouter.com/start/framework/route-module#clientloader

When you don't export a custom client loader, React Router will use a default one that works like the snippet above, calling the server loader for you.

When you export a custom client loader, you take control and it's up to you to decide whether you'll call the server loader or not. It seems you're expecting the server loader to run automatically even when you export a custom client l…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@davidbielik
Comment options

@gustavopch
Comment options

Answer selected by davidbielik
@davidbielik
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants