-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide response code for SSR via react component
- Loading branch information
Showing
4 changed files
with
40 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./lib/response') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Children, Component } from 'react' | ||
import { node, number } from 'prop-types' | ||
import withSideEffect from 'react-side-effect' | ||
|
||
@withSideEffect( | ||
propsList => { | ||
const props = propsList[propsList.length - 1] | ||
if (props) { | ||
return props.statusCode | ||
} | ||
|
||
return undefined | ||
}, | ||
() => {}, | ||
) | ||
export default class Response extends Component { | ||
static propTypes = { | ||
children: node, | ||
statusCode: number, | ||
} | ||
|
||
render() { | ||
if (this.props.children) { | ||
return Children.only(this.props.children) | ||
} | ||
|
||
return null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters