Option 1: Using react-error-boundary
React-error-boundary - is a lightweight package ready to use for this scenario with TS support built-in. This approach also lets you avoid class components that are not that popular anymore.
Options 2: Writing your custom error boundary component
If you don't want to add a new npm package for this, you can also write your own