Skip to main content

IS_CLIENT_SIDE

import { IS_CLIENT_SIDE } from '@dr.pogodin/react-utils';

Equals true within the client-side (browser) environment, and equals false at the server-side (NodeJS).

Beware

It relies on Babel and Webpack configurations provided by react-utils library being used by the host code, along with provided mechanics for server creation and client-side app initialization. It won't work correctly with a different app setup.

INFO

For the purpose of .IS_CLIENT_SIDE and .IS_SERVER_SIDE constants the client- and server-side are distinguished based on the presence in the environment of the process object with Node version stored at its process.versions.node path.

For the test purposes the library provides JU.mockClientSide() and JU.unmockClientSide() functions, which enforce client side values of these constants by removing / restoring process.versions.node value.

Alternatively, the client-side may be enforced by setting true the global REACT_UTILS_FORCE_CLIENT_SIDE variable.