# react-http-status-code

> React HTTP status code allows you to set status codes from react components

Latest version **1.0.1** (published 2019-07-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-http-status-code
pnpm add react-http-status-code
yarn add react-http-status-code
bun add react-http-status-code
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-07-13 |
| First published | 2019-07-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=8.9 |
| Dependencies | 2 |
| Unpacked size | 12.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | daviddentoom |

## Links

- npm: https://www.npmjs.com/package/react-http-status-code
- Repository: https://github.com/daviddt/react-http-status-code
- Homepage: https://github.com/daviddt/react-http-status-code#readme
- Issues: https://github.com/daviddt/react-http-status-code/issues
- npm.io page: https://npm.io/package/react-http-status-code

## Dependencies (2)

- [react-side-effect](https://npm.io/package/react-side-effect.md) ^1.1.5
- [@types/react-side-effect](https://npm.io/package/@types/react-side-effect.md) ^1.1.1

## Recent versions

- 1.0.1 (latest) — 2019-07-13

## README

# react-http-status-code

React HTTP status code allows you to set status codes from react components

## Install
npm install --save react-http-status-code

## Client usage
```javascript
import React from "react";
import { StatusCode } from "react-http-status-code";

// render your component
const MyComponent = () => (
    <StatusCode code={404}>
        <div>
            <p>Sorry, page was not found</p>
        </div>
    </StatusCode>   
);
```

## Server usage
```javascript
import React from "react";
import { renderToString } from "react-dom/server";
import { StatusCode } from "react-http-status-code";

// express middleware
const renderPage = (req, res, next) => {

    const html = renderToString(
        React.createElement(MyRootComponent, props)
    );

    // call this AFTER rendering to string!
    const status = StatusCode.rewind();

    // send the status if one was defined
    if (status) res.status(status);

    res.send(html);
};
```

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