package
Helpers to only render React components in a browser (not SSR)
npm install react-client-onlyGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 1 packages.
8.7 kB
Includes dependencies.
This package provides a utility component and a React hook for only rendering React components in the browser, but not during server-side rendering.
This is useful for static-side generation when trying to avoid rehydration issues, e.g. for components dependent on the current user.
Inspired & based on the examples in this blog post.
import React from "react";
import { ClientOnly, useClientOnly } from "react-client-only";
const component = () => (
<div>
<p>This will render during SSR and on the client.</p>
<ClientOnly>
<p>This will render on the client only.</p>
</ClientOnly>
</div>
);
// or
const component2 = () => {
const isOnClient = useClientOnly
# If you're using yarn
yarn add react-client-only
# If you're npm
npm install react-client-only