{prev}; } function B() { return {externalState}; } render(( <> </> )); ``` In the above example, even though both `A` and `B` uses `externalState`, they yield different results as `A` is an impure component for mutating `externalState` during render, which causes `B` to receive a different value from `A`. ## What if I don't know this? No worries, React has a component called `` which performs the processes *twice* to detect unwanted side-effects, which includes: - Updating refs before reading. - Re-rendering other components while another component is rendering. - Detecting usage of deprecated APIs (unsafe lifecycles, legacy context, etc.) This behavior is also enabled by default in the upcoming React 18. However, this feature does not cover behavior that are not tied to the React environment (e.g. external states such as Redux stores). ## So, where to do these side-effects? React has a dedicated hook which is, as you guessed it, `useEffect` and `useLayoutEffect`. These hooks have a dedicated timeframe to perform side-effects in a such way that it is not intrusive to the render process of React. ## References - [StrictMode](https://reactjs.org/docs/strict-mode.html) - [Rule of React](https://gist.github.com/sebmarkbage/75f0838967cd003cd7f9ab938eb1958f)" data-react-helmet="true" />{prev}; } function B() { return {externalState}; } render(( <> </> )); ``` In the above example, even though both `A` and `B` uses `externalState`, they yield different results as `A` is an impure component for mutating `externalState` during render, which causes `B` to receive a different value from `A`. ## What if I don't know this? No worries, React has a component called `` which performs the processes *twice* to detect unwanted side-effects, which includes: - Updating refs before reading. - Re-rendering other components while another component is rendering. - Detecting usage of deprecated APIs (unsafe lifecycles, legacy context, etc.) This behavior is also enabled by default in the upcoming React 18. However, this feature does not cover behavior that are not tied to the React environment (e.g. external states such as Redux stores). ## So, where to do these side-effects? React has a dedicated hook which is, as you guessed it, `useEffect` and `useLayoutEffect`. These hooks have a dedicated timeframe to perform side-effects in a such way that it is not intrusive to the render process of React. ## References - [StrictMode](https://reactjs.org/docs/strict-mode.html) - [Rule of React](https://gist.github.com/sebmarkbage/75f0838967cd003cd7f9ab938eb1958f)" data-react-helmet="true" />{prev}; } function B() { return {externalState}; } render(( <> </> )); ``` In the above example, even though both `A` and `B` uses `externalState`, they yield different results as `A` is an impure component for mutating `externalState` during render, which causes `B` to receive a different value from `A`. ## What if I don't know this? No worries, React has a component called `` which performs the processes *twice* to detect unwanted side-effects, which includes: - Updating refs before reading. - Re-rendering other components while another component is rendering. - Detecting usage of deprecated APIs (unsafe lifecycles, legacy context, etc.) This behavior is also enabled by default in the upcoming React 18. However, this feature does not cover behavior that are not tied to the React environment (e.g. external states such as Redux stores). ## So, where to do these side-effects? React has a dedicated hook which is, as you guessed it, `useEffect` and `useLayoutEffect`. These hooks have a dedicated timeframe to perform side-effects in a such way that it is not intrusive to the render process of React. ## References - [StrictMode](https://reactjs.org/docs/strict-mode.html) - [Rule of React](https://gist.github.com/sebmarkbage/75f0838967cd003cd7f9ab938eb1958f)" data-react-helmet="true" />omniquotient