This examples walks through a series of different situations in which an error may be thrown, explores what happens, and what can be done about it.
Each card has a link to its source code (on GitHub) at the top, as well as a summary of the setup.
Errors thrown in components will cause the page to crash. React has a standard solution to this: Error Boundaries
However, Error Boundaries do not work for async functions/promises.
The hard problem in handling errors in functional components in React is dealing with errors from async functions/promises.
Two solutions are presented: via react-error-boundary and via a global event mechanism.
react-error-boundary can be a good way to take advantage of a standard global error handling mechanism on a per-component level.
However, for general-purpose tools (e.g. an internal http client that wraps a backend API) that exist outside of components, or that would benefit from not having to think about error handling each time - it may make sense to opt for a global event mechanism to tie the world of react with the outside world.