Socket
Socket
Sign inDemoInstall

react-control-render

Package Overview
Dependencies
8
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-control-render

Easy-to-use tool to handle the content that needs to be rendered only on the client-side or on the server-side


Version published
Weekly downloads
2
increased by100%
Maintainers
1
Install size
3.37 MB
Created
Weekly downloads
 

Readme

Source

react-control-render

Easy-to-use tool to handle the content that needs to be rendered only on the client-side or on the server-side.

Installation

Install with npm:

npm i react-control-render

or with yarn:

yarn add react-control-render

Usage

If you need some content to be rendered only on the server-side or on the client-side, you just need to import the ClientOnly or ServerOnly component and wrap it around the needed content:

import React from 'react';
import {ClientOnly, ServerOnly} from 'react-control-render';

const TestRender = () => {
  return (
    <div>
      <ServerOnly>This text is rendered only on the server-side</ServerOnly>
      <ClientOnly>This text is rendered only on the client-side</ClientOnly>
    </div>
  );
};

export default TestRender;

Alternately, you can use the useRender hook approach:

import React from 'react';
import {useRender} from 'react-control-render';

const TestRender = () => {
  const {isClient, isServer} = useRender();

  return (
    <div>
      {isClient && <>Client Text</>
      {isServer && <>Server Text</>
    </div>
  );
};

export default TestRender;

Keywords

FAQs

Last updated on 18 Apr 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