react-control-render
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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;

Package Sidebar

Install

npm i react-control-render

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

4.53 kB

Total Files

4

Last publish

Collaborators

  • yelysei