
Description
react-body-classname is a small React helper for setting the class name on the document body from inside your components. Instead of changing document.body by hand, you describe the classes declaratively, and components nested in your tree can each add their own. The component is stateful, so the combined class name stays in step with what is mounted. It is built on React Side Effect and also works on the server. After rendering to a string, you call BodyClassName.rewind() to get the combined class names and insert them into your HTML template. The package is installed from npm and needs React 0.13 or later. The README notes two things to keep in mind: only a single child is supported in its props, and the server rewind call must be made, because the component keeps track of mounted instances and skipping it causes a memory leak. The project is open source on GitHub.…
Highlights
- Declarative body class names from React components
- Nested components can add their own classes
- Server-side rendering with rewind()
- Works with React 0.13 and later
Ratings & Reviews
No ratings yet
Be the first to rate react-body-classname.
People also visit

react-css-modules
Seamless mapping of class names to CSS modules inside of React components
react-body-classname FAQ
What does react-body-classname do?
It sets document.body.className declaratively from React components, so each part of your tree can add the classes it needs.
How do I install it?
Install the react-body-classname package from npm. It needs React 0.13 or later.
Can it be used on the server?
Yes. Call BodyClassName.rewind() after rendering to a string, then put the combined class name into your HTML template.
What should I watch out for?
It supports only a single child in its props. On the server you must call rewind(), since the component tracks mounted instances and skipping it leaks memory.
Is it free?
The source is public on GitHub, which is where it is distributed.
What are the best react-body-classname alternatives?
Popular alternatives to react-body-classname include react-css-modules, react-bem-helper and react-document-title. See all react-body-classname alternatives




















