From 5b3f6358f7de462acd98b8631de9e7e34aeaffac Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Thu, 21 Sep 2023 08:26:18 +0600 Subject: [PATCH] wip: add strict mode question --- .../react/content/strict-mode.md | 19 +++++++++++++++++++ src/data/question-groups/react/react.md | 5 +++++ 2 files changed, 24 insertions(+) create mode 100644 src/data/question-groups/react/content/strict-mode.md diff --git a/src/data/question-groups/react/content/strict-mode.md b/src/data/question-groups/react/content/strict-mode.md new file mode 100644 index 000000000..9cb1350cc --- /dev/null +++ b/src/data/question-groups/react/content/strict-mode.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( + + + +); +``` + +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. diff --git a/src/data/question-groups/react/react.md b/src/data/question-groups/react/react.md index 3bbbce882..602832a36 100644 --- a/src/data/question-groups/react/react.md +++ b/src/data/question-groups/react/react.md @@ -295,4 +295,9 @@ questions: topics: - 'SSR' - 'Intermediate' + - question: What is Strict Mode in React and why is it useful? + answer: strict-mode.md + topics: + - 'Debugging' + - 'Intermediate' ---