Preact: Support for componentDidCatch

Created on 7 Aug 2017  路  6Comments  路  Source: preactjs/preact

Error handling with preact/react is anything but pleasant at the moment. componentDidCatch should make the process a little bit easier.

enhancement in X

Most helpful comment

Closing, componentDidCatch is now available in master :+1:

All 6 comments

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:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

paulkatich picture paulkatich  路  3Comments

marcosguti picture marcosguti  路  3Comments

simonjoom picture simonjoom  路  3Comments

SabirAmeen picture SabirAmeen  路  3Comments

mizchi picture mizchi  路  3Comments