React & Modern Frontend (445 Qs)•Part 8: Advanced React Patterns, Portals & Performance (152 - 261)
What is the benefit of strict mode?
The <StrictMode> will be helpful in the below cases,
- To find the bugs caused by impure rendering where the components will re-render twice.
- To find the bugs caused by missing cleanup of effects where the components will re-run effects one more extra time.
- Identifying components with unsafe lifecycle methods.
- Warning about legacy string ref API usage.
- Detecting unexpected side effects.
- Detecting legacy context API.
- Warning about deprecated findDOMNode usage
Practical Code Example
jsx
// StrictMode benefits:
// In development, React double-invokes render and effects to expose accidental side-effects:
<React.StrictMode>
<App />
</React.StrictMode>