File size: 978 Bytes
6bcb42f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import React from 'react';
import ErrorBoundary from '../containers/error-boundary.jsx';

/*
 * Higher Order Component to provide error boundary for wrapped component.
 * A curried function, call like errorHOC(<tracking label>)(<Component>).
 * @param {string} action - Label for GA tracking of errors.
 * @returns {function} a function that accepts a component to wrap.
 */
const ErrorBoundaryHOC = function (action){
    /**
     * The function to be called with a React component to wrap it.
     * @param {React.Component} WrappedComponent - Component to wrap with an error boundary.
     * @returns {React.Component} the component wrapped with an error boundary.
     */
    return function (WrappedComponent) {
        const ErrorBoundaryWrapper = props => (
            <ErrorBoundary action={action}>
                <WrappedComponent {...props} />
            </ErrorBoundary>
        );
        return ErrorBoundaryWrapper;
    };
};

export default ErrorBoundaryHOC;