React with Webpack + babel support

Download the code React with Webpack + babel support

React ErrorBoundary code snippet


import React, { Component } from 'react';

class ErrorBoundary extends Component {
    state = {
        hasError: false,
        errorMessage: ''
    }

    componentDidCatch = (errorinfo=> {
        this.setState({hasError: trueerrorMessage: error});
    }

    render() {
        if (this.state.hasError) {
            return <h1>{this.state.errorMessage}</h1>;
        } else {
            return this.props.children;
        }
    }
}

export default ErrorBoundary;