Skip to content

Instantly share code, notes, and snippets.

@robbertvancaem
Last active December 9, 2019 08:32
Show Gist options
  • Save robbertvancaem/0a01cafebed5ee5aa985a17c33263d50 to your computer and use it in GitHub Desktop.
Save robbertvancaem/0a01cafebed5ee5aa985a17c33263d50 to your computer and use it in GitHub Desktop.
dynamic-routing-now-7
// 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