HOC to display errors related to a component. Shows stack trace details.
$ npm install --save react-bootstrap-hoc-error
With decorators
import React from 'react';
import errorHOC from 'react-bootstrap-hoc-error');
@errorHOC()
class MyComponent extends React.Component {
render() {
return (
<div>
{this.renderError()}
</div>
)
}
}
<MyComponent> // <div></div>
<MyComponent error="An error"> // <div><ErrorComponent error="An error"></div>
Learn more about the default ErrorComponent
errorHOC.setDefaultErrorComponent(({ error }) => <span>{error}</span>);
<MyComponent error="An error"> // <div><span>An error</span></div>
@errorHOC({ ErrorComponent: ({ error }) => <span>{error}</span> })
class MyComponent extends React.Component { ... }
<MyComponent error="An error"> // <div><span>An error</span></div>
@errorHOC({ errorPropName: 'myProp' })
class MyComponent extends React.Component { ... }
<MyComponent error="An error"> // <div></div>
<MyComponent myProp="An error"> // <div><ErrorComponent error="An error" /></div>
The displayName
of the extended component will be preserved unless the fullDisplayName
option is passed
@errorHOC()
class MyComponent extends React.Component { ... }
MyComponent.displayName === 'MyComponent';
@errorHOC({ fullDisplayName: true })
class MyComponent extends React.Component { ... }
MyComponent.displayName === 'Error(MyComponent)';