if (isHydrated) { return <ClientOnlyComponent />; }
return <ServerFallback />; }
When doing SSR, the value of isHydrated will always be false. The first client-side render isHydrated will still be false, and then it will change to true.
After the first client-side render, future components rendered calling this hook will receive true as the value of isHydrated. This way, your server fallback UI will never be rendered on a route transition.
Install using
bunx shadcn@latest add @remix-utils/use-hydrated.This depends on
react.This hook lets you detect if your component is already hydrated. This means the JS for the element loaded client-side and React is running.
With useHydrated, you can render different things on the server and client while ensuring the hydration will not have a mismatched HTML.
When doing SSR, the value of
isHydratedwill always befalse. The first client-side renderisHydratedwill still be false, and then it will change totrue.After the first client-side render, future components rendered calling this hook will receive
trueas the value ofisHydrated. This way, your server fallback UI will never be rendered on a route transition.Author
Sergio XalambrÃ