2 ms·
Since people in the early days of React would ignore errors thrown by components (or the React library itself) and constantly run into literal undefined behavio
by koito17 2y ago
Since people in the early days of React would ignore errors thrown by components (or the React library itself) and constantly run into literal undefined behavior, React eventually adopted a behavior where it unmounts the VDOM to catch the developer's attention.[0] When a component throws an error, React will unmount to the nearest error boundary. By default, this is the root of the tree. You can control how much gets unmounted with error boundaries.
I've never used Vue so I have no idea how error handling works there, but React also offers programmatic ways to recover from errors (e.g. error boundaries can retry rendering the failed component with different state or props). Doesn't sound strange to me.
[0] https://legacy.reactjs.org/docs/error-boundaries.html https://legacy.reactjs.org/docs/error-boundaries.html
- chuckadams 2y agoIn Vue, if a component's setup or render functions crash, the component and its children just don't render and the parent is unaffected. It doesn't unmount components that crash later either. I guess that means Vue has an implicit error boundary around every component, and if you want different behavior, you set the errorCaptured hook to do something else.