# react-html-classname

> A declarative, nested way to manipulate your html's className

Latest version **0.1.2** (published 2017-10-03) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install react-html-classname
pnpm add react-html-classname
yarn add react-html-classname
bun add react-html-classname
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2017-10-03 |
| First published | 2016-08-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Thomas Sloboda |
| Maintainers | thomassloboda |
| Keywords | react, component, react-component, html.className, title, jsx |

## Links

- npm: https://www.npmjs.com/package/react-html-classname
- Repository: https://github.com/thomassloboda/react-html-classname
- Issues: https://github.com/thomassloboda/react-html-classname/issues
- npm.io page: https://npm.io/package/react-html-classname

## Dependencies (4)

- [prop-types](https://npm.io/package/prop-types.md) ^15.6.0
- [lodash.uniq](https://npm.io/package/lodash.uniq.md) ^4.5.0
- [react-side-effect](https://npm.io/package/react-side-effect.md) ^1.0.0
- [create-react-class](https://npm.io/package/create-react-class.md) ^15.6.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2017-10-03
- 0.1.1 — 2016-08-19
- 0.1.0 — 2016-08-19

## README

React Html ClassName
====================

Provides a declarative way to specify `document.getElementsByTagName("html")[0].className` in a single-page app.  
This component can be used on server side as well.

Built with [React Side Effect](https://github.com/gaearon/react-side-effect).

====================

## Installation

```
npm install --save react-html-classname
```

Dependencies: React >= 0.13.0

## Features

* Does not emit DOM, not even a `<noscript>`;
* Like a normal React compoment, can use its parent's `props` and `state`;
* Can be defined in many places throughout the application;
* Supports arbitrary levels of nesting, combining each className;
* Works just as well with isomorphic apps.

## Example

```jsx
class SomeComponent {
  render() {
    // This will add 'home' to the html
    return (
      <HtmlClassName className='home'>
        <h1>Home, sweet home.</h1>
      </HtmlClassName>
    );
  }
}

class App {
  render() {
    // This will add 'app' to the html
    return (
      <HtmlClassName className='app'>
        <SomeComponent/>
      </HtmlClassName>
    );
    // Becaase we nested the component, our html will now have 'app home'
    // as the class name
  }
}
```

Use CSS modules with webpack or similar?

```jsx
import styles from './some.css';

class Thing {
  render() {
    return (
      <HtmlClassName className={styles.html}>
        <h1>CSS modules rock!</h1>
      </HtmlClassName>
    );
  }
}
```

## Server Usage

If you use it on server, call `HtmlClassName.rewind()` **after rendering components to string** to retrieve the combined class name. You can then embed this className into HTML page template.

Because this component keeps track of mounted instances, **you have to make sure to call `rewind` on server**, or you'll get a memory leak.

---
_Source: https://npm.io/package/react-html-classname · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
