wip: add strict mode question

feat/questions
Arik Chakma 1 year ago
parent 0675572f8b
commit 5b3f6358f7
  1. 19
      src/data/question-groups/react/content/strict-mode.md
  2. 5
      src/data/question-groups/react/react.md

@ -0,0 +1,19 @@
Strict Mode is a tool in React for highlighting potential problems in an application. By wrapping a component tree with `StrictMode`, React will activate additional checks and warnings for its descendants. This doesn't affect the production build but provides insights during development.
```js
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
const root = createRoot(document.getElementById('root'));
root.render(
<StrictMode>
<App />
</StrictMode>
);
```
In Strict Mode, React does a few extra things during development:
1. It renders components twice to catch bugs caused by impure rendering.
2. It runs side-effects (like data fetching) twice to find mistakes in them caused by missing effect cleanup.
3. It checks if deprecated APIs are used, and logs a warning message to the console if so.

@ -295,4 +295,9 @@ questions:
topics: topics:
- 'SSR' - 'SSR'
- 'Intermediate' - 'Intermediate'
- question: What is Strict Mode in React and why is it useful?
answer: strict-mode.md
topics:
- 'Debugging'
- 'Intermediate'
--- ---

Loading…
Cancel
Save