# react-declarative-head

> Head side effects handled with a declarative component

Latest version **1.0.5** (published 2016-11-29) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-declarative-head
pnpm add react-declarative-head
yarn add react-declarative-head
bun add react-declarative-head
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2016-11-29 |
| First published | 2016-11-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Maintainers | josepapaianni |
| Keywords | react, component, react-component, head, document.title, tags, jsx |

## Links

- npm: https://www.npmjs.com/package/react-declarative-head
- Repository: https://github.com/josepapaianni/react-declarative-head
- Homepage: https://github.com/josepapaianni/react-declarative-head#readme
- Issues: https://github.com/josepapaianni/react-declarative-head/issues
- npm.io page: https://npm.io/package/react-declarative-head

## Dependencies (3)

- [react](https://npm.io/package/react.md) ^15.3.2
- [react-dom](https://npm.io/package/react-dom.md) ^15.3.2
- [shallowequal](https://npm.io/package/shallowequal.md) ^0.2.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

- 1.0.5 (latest) — 2016-11-29
- 1.0.4 — 2016-11-26
- 1.0.3 — 2016-11-25
- 1.0.2 — 2016-11-21
- 1.0.1 — 2016-11-21
- 1.0.0 — 2016-11-21

## README

# React Declarative Head

React component to handle `<head>` side effects on client and server side.

Inspired in [React Side Effect](https://github.com/gaearon/react-side-effect).

## Installation

```sh
npm install react-declarative-head --save
```

## Use Cases
* Keep `<head>` stuff in your app structure
* Add/remove `<head>` tags along your application

## Usage

```js
import React, { Component } from 'react';
import Head from 'react-declarative-head';

const Foo = props =>
  <div>
    <Head>
      <title>A New Hello World!</title>
      <link rel="preconnect" href="https://www.to.a.new.preconnect.com/" />
    </Head>
  </div>

const MyApp = props =>
  <div>
    <Head>
      <title>Hello World!</title>
      <link rel="preconnect" href="https://www.google.com/" />
    </Head>
    <Foo />
  </div>

```

On the server you can call `Head.rewind()` to get the current state as a HTML string to inject in your response.

```js
app.get('*', (req, res) => {
  const app = ReactDOMServer.renderToString(
    <MyApp />
  );

  res.send(`<!DOCTYPE><html>
  <head>${Head.rewind()}</head>
  <body><div id="app-root">${app}</div>
  <script src="myapp-bundle.js"></script>
  </body></html>`)
});
```

If you are server rendering and forget to call `Head.rewind()` after `renderToString()` you'll get a memory leak.

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