useIsClient

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

Install:

npm i @uidotdev/usehooks

Description:

The useIsClient hook is useful for determining whether the code is running on the client-side or server-side. The hook initializes a state variable called “isClient” and sets its initial value to false. This information can be utilized in conditional rendering, handling browser-specific behavior, or making API calls that should only be executed on the client-side.

Parameters

The useIsClient hook does not accept any parameters.

Return Value

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

Demo:

Example:

Related Hooks: