A declarative, nested way to manipulate your body's className
npm install react-body-classname-existingdocument.body.className in your react app. Supports server-side usage too.
yarn add react-body-classname
`
Dependencies: React >= 0.13.0
What it looks like
`jsx
import BodyClassName from 'react-body-classname';
const Basic = () => (
You ate a whole wheel of cheese?
);
// -> document.body.className === "helloworld"
const Nested = () => (
I‘m not even mad
);
// -> document.body.className === "outside inside"
const GoCrazy = () => (
I'm impressed
);
// -> 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.