Error catching
Just like React, Proton provides an interface to catch errors thrown in children components.
function Child() { throw new Error("Test") }
function Parent(this: Proton.Component) {
this.catch(thrown => { /* Do something */ })
return <div><Child /></div>
}
The parent can catch its own errors that happens after catch
declaration.
function Parent(this: Proton.Component) {
this.catch(thrown => { /* Do something */ })
throw new Error("parent error")
}
Event handlers are also caught, though they don't break the component view if they error.
function Child(this: Proton.Component) {
// This will catch a event handler error.
this.catch(thrown => { /* Do something */ })
return <button on={{ click: () => { throw new Error("Test") } }} />
}