Socket
Socket
Sign inDemoInstall

react-body-classname

Package Overview
Dependencies
7
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-body-classname

A declarative, nested way to manipulate your body's className


Version published
Maintainers
2
Install size
183 kB
Created

Readme

Source

react-body-classname

NPM version Downloads Dependency status

Provides a declarative way to specify document.body.className in your react app. Supports server-side usage too.

Built with React Side Effect.


Install

yarn add react-body-classname

Dependencies: React >= 0.13.0

What it looks like

import BodyClassName from 'react-body-classname';

const Basic = () => (
  <BodyClassName className="helloworld">
    <h1>You ate a whole wheel of cheese?</h1>
  </BodyClassName>
);
// -> document.body.className === "helloworld"

const Nested = () => (
  <BodyClassName className="outside">
    <div>
      <BodyClassName className="inside">
        <p>I‘m not even mad</p>
      </BodyClassName>
    </div>
  </BodyClassName>
);
// -> document.body.className === "outside inside"

const GoCrazy = () => (
  <BodyClassName className={Array(8).join(''/0) + ' batman!'}>
    <h1>I'm impressed</h1>
  </BodyClassName>
);
// -> document.body.className === "NaNNaNNaNNaNNaNNaNNaN batman!"

Note: Only supports a single child as props.

Server Usage

When using server-side, use BodyClassName.rewind() after rendering components to string to retrieve the combined class name. Then chuck that into your HTML template.

Important: This component keeps track of mounted instances, so if you don't call BodyClassName.rewind() you'll get a memory leak.

Keywords

FAQs

Last updated on 19 Sep 2019

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