Socket
Socket
Sign inDemoInstall

react-client-only

Package Overview
Dependencies
3
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-client-only

Helpers to only render React components in a browser (not SSR)


Version published
Maintainers
1
Weekly downloads
510
decreased by-25.87%
Bundle size
298 bytes
Minified + gzipped

Weekly downloads

Readme

Source

react-client-only

Github license Open issues Closed issues Open Pull Requests Closed Pull Requests

Known Vulnerabilities Dependencies DevDependencies OptionalDependencies PeerDependencies Code Climate issues Code Climate maintainability Code Climate maintainability (percentage) Code Climate technical debt

NPM license Known Vulnerabilities

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.

Usage

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 (!isOnClient) {
    return null;
  }

  return <p>This will render on the client only.</p>;
};

Install

# If you're using yarn
yarn add react-client-only

# If you're npm
npm install react-client-only

Keywords

FAQs

Last updated on 03 Mar 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc