Is there a way in React -- either in code or via the React devtools -- to see if a component is being rendered in React's StrictMode
? In my dream world, there would be some kind of constant I could console.log
, say a bool of React.isStrictModeOnForThisComponentRendering
; or maybe when you inspect a component in the React devtools, it would say somewhere in the side panel if it's rendering in StrictMode or not.
To be clear, this question is:
- Not about how do you enable StrictMode. (The answer is
<React.StrictMode>
, although it can also be set via configs in some frameworks, e.g.,Next.js
) - Specifically discussing React's
StrictMode
, not JavaScript's ('use strict';
) or TypeScript's strict mode. It's an overloaded phrase, but watcha gonna do? - Motivated by the confusion you get due to unexpected double rendering with React's StrictMode. See this GitHub issue or this StackOverflow post for a sense of the frustration it can cause. It would be nice to have an easy way to verify a component is running in StrictMode even if you can't tell where in the component tree StrictMode has been enabled.