Why do not you need error boundaries for event handlers?

Posted by Prem Tiwari | Updated on

Why do not you need error boundaries for event handlers?

Error boundaries do not catch errors inside event handlers. Event handlers don’t happened or invoked during rendering time unlike render method or lifecycle methods. So React knows how to recover these kind of errors in event handlers. If still you need to catch an error inside event handler, use the regular JavaScript try / catch statement as below

The above code is catching the error using vanilla javascript try/catch block instead of error boundaries.


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers