From eafba20b3de58cb7f8453cb4985c4ae7953d5d11 Mon Sep 17 00:00:00 2001 From: Federico Zivolo <5382443+FezVrasta@users.noreply.github.com> Date: Sat, 14 Nov 2020 13:26:15 +0100 Subject: [PATCH] docs: document prod vs dev behavior difference in componentDidCatch (#2168) --- content/docs/reference-react-component.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/content/docs/reference-react-component.md b/content/docs/reference-react-component.md index 1eeb9c4b..37a5a9b8 100644 --- a/content/docs/reference-react-component.md +++ b/content/docs/reference-react-component.md @@ -413,6 +413,12 @@ class ErrorBoundary extends React.Component { } ``` +Production and development builds of React slightly differ in the way `componentDidCatch()` handles errors. + +On development, the errors will bubble up to `window`, this means that any `window.onerror` or `window.addEventListener('error', callback)` will intercept the errors that have been caught by `componentDidCatch()`. + +On production, instead, the errors will not bubble up, which means any ancestor error handler will only receive errors not explictly caught by `componentDidCatch()`. + > Note > > In the event of an error, you can render a fallback UI with `componentDidCatch()` by calling `setState`, but this will be deprecated in a future release.