Skip to content

Instantly share code, notes, and snippets.

@mb8z
Last active October 2, 2018 14:53
Show Gist options
  • Save mb8z/96c5166af31e70501de30da4f8b4c754 to your computer and use it in GitHub Desktop.
Save mb8z/96c5166af31e70501de30da4f8b4c754 to your computer and use it in GitHub Desktop.
import React from 'react';
import _ from 'lodash';
import {
withState,
compose,
lifecycle,
} from 'recompose';
const withErrorCatch = ErrorComponent => compose(
withState('errorComponent', 'setErrorComponent', null),
lifecycle({
// NOTE: For testing
// componentDidMount() {
// const { setErrorComponent } = this.props;
// const passedProps = {
// ..._.omit(this.props, ['children']),
// errorFromComponent: {},
// };
// console.log('Error set');
// setErrorComponent(<ErrorComponent {...passedProps} />);
// },
componentDidCatch(error, errorInfo) {
const { setErrorComponent } = this.props;
const passedProps = {
..._.omit(this.props, ['children']),
errorFromComponent: {
error,
errorInfo,
},
};
setErrorComponent(<ErrorComponent {...passedProps} />);
},
}),
);
export default {
withErrorCatch,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment