Effects

useIsClient

Reports false on the server and true after hydration.

Demo

Server / first render
isClient
false

The panel starts as the server markup, then swaps after hydration — gate browser-only UI (portals, media queries) on this so the two renders match.

Usage

use-is-client.tsxtsx
import { useIsClient } from "hookli";

export function Demo() {
  const isClient = useIsClient();

  if (!isClient) return <p>Rendering on the server…</p>;

  return <p>Now running in the browser.</p>;
}

API

useIsClient.d.tsts
useIsClient(): boolean

Parameters

This hook takes no parameters.

Returns

NameTypeDescription
isClientbooleanfalse during server rendering and the first hydration pass, then true once mounted in the browser. Gate browser-only UI on it to keep both renders identical.

Hook

The implementation, straight from hookli. Copy it, or install the package.

src/hooks/use-is-client/use-is-client.tstsx
import { useEffect, useState } from "react";

export const useIsClient = () => {
  const [isClient, setIsClient] = useState(false);

  useEffect(() => {
    setIsClient(true);
  }, []);

  return isClient;
};

View source on GitHub

Related hooks