Skip to main content

useIsClient

function useIsClient(): boolean;

Returns false during server rendering and on the first render while hydrating, then true. Use it to render content that only makes sense in the browser, such as something that reads localStorage or the user's time zone, without the server's HTML and the first client render disagreeing.

In an app without server rendering it is true from the very first render, so unlike the common useEffect version it costs no extra render.

Example​

import { useIsClient } from "react-honey-hooks";

function LocalTime({ date }: { date: Date }) {
const isClient = useIsClient();

// The server doesn't know the user's time zone, so it renders a placeholder.
return <time>{isClient ? date.toLocaleTimeString() : "--:--"}</time>;
}