A nested, stateful status code thing for React. Based on react-document-title.
npm install react-nested-statusReact Nested Status
===================
A server-side utility component that passes status codes. Useful to set HTTP status codes based on which components are being rendered.
Built with React Side Effect.
Based (heavily) on React Document Title.
====================
```
npm install --save react-nested-status
Dependencies: React >= 0.11.0
* Made for isomorphic apps. Really doesn't have a use without server-side React.
* Does not emit DOM, not even a
Assuming you use something like react-router:
`javascript
var App = React.createClass({
render: function () {
// Use "My Web App" if no child overrides this
return (
);
}
});
var HomePage = React.createClass({
render: function () {
// Use "Home" while this component is mounted
return (
Home, sweet home.
);
}
});
var ErrorPage = React.createClass({
mixins: [LinkStateMixin],
render: function () { Page not found.
// Update using value from state while this component is mounted
return (
Four-oh-four
);
}
});
`
Call NestedStatus.rewind() after rendering components to string to retrieve the status code given to the innermost NestedStatus. You can then use this to set your Express (or other web server) status code.
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.
`javascript
var markup = React.renderToString(React.createFactory(Handler)());
var status = NestedStatus.rewind();
var html = React.renderToStaticMarkup(htmlComponent({
markup: markup
}));
// Express
res.status(status).send('' + html);
``
A huge thanks to gaearon for his open-source React Document Title that was easy to understand and modify.