useIsClient

Determine whether the code is running on the client-side or server-side with useIsClient.

Install:

npm i @uidotdev/usehooks

Description:

useIsClient is useful for determining if it’s safe to run certain client-only hooks like useMediaQuery or useLocalStorage. It returns a boolean determining if React’s useEffect hook has finished running (which means the app is being rendered on the client and it’s safe to use browser specific APIs).

Parameters

The useIsClient hook does not accept any parameters.

Return Value

NameTypeDescription
isClientbooleantrue if running in a client-side environment, false otherwise.

Demo:

Example:

More Hooks:

Sort: