#useRouterState - documentation?

5 messages · Page 1 of 1 (latest)

rough patio
#

Hi, I saw this in the Kitchen Sink React Query File Based example in __root.tsx:

  const isLoading = useRouterState({ select: (s) => s.status === 'pending' })
  return <Spinner show={isLoading} />
}```

Is there any documentation for `useRouterState()`. I like the idea of a global spinner, but I wasn't quite sure how this all worked and so far couldn't find any documentation for this hook.
dire tangle
#

You can set the RouterSpinner as defaultPendingComponent in the router options

rough patio
#

I see that is an option, by my original question still kind of stands: Is there documentation for the useRouterState hook / is it a recommended approach?

tawdry kraken
#

In the meantime, the TLDR is that the hook is useful to tapping into the internal state the router uses for tracking changes and handling location commits and whatnot.
In user-land, you should be able to easily navigate the hook's params and output using typescript's autocomplete.

I personally use it mostly for the transition use-case you mentioned above, and for accessing the current location.

const location = useRouterState({ select: (s) => s.location });

The selector is making sure you only capture what you need and don't trigger too many renders.