React ErrorBoundary
在开发环境中失效
如下:
https://codesandbox.io/p/sandbox/react-error-boundary-example...
https://codesandbox.io/p/sandbox/react-error-boundary-example...
包括官网的例子:
https://codesandbox.io/p/sandbox/epic-night-mt4t4f
唯独在文档的例子是正常的:
https://react.dev/reference/react/useTransition#displaying-an...
线上环境:https://codepen.io/levi0001/pen/VwNabQR
提供一个线上环境,能够正常演示ErrorBoundary
问题:在开发环境调试ErrorBoundary
的fallbak UI,正确姿势应该怎么做呢?
排除两个做法:
- 将fallback UI当做正常的UI画出来,确认后加到
ErrorBoundary
,因为fallback UI可能会作为props
传入,不可能每次传值都这么做一遍; - 每次调试都生成一遍
production