Last active
December 9, 2019 08:32
-
-
Save robbertvancaem/0a01cafebed5ee5aa985a17c33263d50 to your computer and use it in GitHub Desktop.
dynamic-routing-now-7
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
// hoc/withError.js | |
import React from 'react'; | |
import Error from '../pages/_error'; | |
export default Component => class extends React.Component { | |
static async getInitialProps(ctx) { | |
const props = await Component.getInitialProps(ctx); | |
const { statusCode } = props; | |
return { statusCode, ...props }; | |
} | |
render() { | |
const { statusCode } = this.props; | |
if (statusCode && statusCode !== 200) { | |
return <Error statusCode={statusCode} {...this.props} />; | |
} | |
return <Component {...this.props} />; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment