开发环境如何调试React ErrorBoundary的fallbak UI?

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,正确姿势应该怎么做呢?

排除两个做法:

  1. 将fallback UI当做正常的UI画出来,确认后加到ErrorBoundary,因为fallback UI可能会作为props传入,不可能每次传值都这么做一遍;
  2. 每次调试都生成一遍production
阅读 421
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题