Error handling with preact/react is anything but pleasant at the moment. componentDidCatch should make the process a little bit easier.
+1
a nice example why we need this:
https://codeburst.io/catching-exceptions-using-higher-order-components-in-react-16-b8a401853a10
Agreed, I would like to see this supported in Preact.
I took a first pass in https://github.com/developit/preact/pull/880. This will catch errors in render, but not those triggered by a click handler for example.
Use a component like this to test:
export default class Test extends Component {
componentDidCatch( error, errorInfo ) {
console.log( error, errorInfo )
}
render() {
throw new Error( 'I crashed!' );
return;
}
}
note: for visibility there's a PR here as well - #819
Closing, componentDidCatch is now available in master :+1:
Most helpful comment
Closing,
componentDidCatchis now available inmaster:+1: