Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

17 Commits

Repository files navigation

konnektid-react-status Build Status

Set the HTTP status code from inside react components

Install

npm install --save konnektid/konnektid-react-status

Client usage

importReactfrom"react";importStatusCodefrom"konnektid-react-status";// render your componentconstMyComponent=()=>(<StatusCodecode={404}><div><p>Sorry, page was not found</p></div></StatusCode>);

Server usage

importReactfrom"react";import{renderToString}from"react-dom/server";importStatusCodefrom"konnektid-react-status";// express middlewareconstrenderPage=(req,res,next)=>{consthtml=renderToString(React.createElement(MyRootComponent,props));// call this AFTER rendering to string!conststatus=StatusCode.rewind();// send the status if one was definedif(status)res.status(status);res.send(html);};

About

Set the HTTP status code from inside React components

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages