출처: React doc
Effects let you run some code after rendering so that you can synchronize your component with some system outside of React.
Keep in mind that Effects are typically used to “step out” of your React code and synchronize with some external system.
👉 useEffect hook은 rendering된 후 useEffect안에 있는 코드가 작동하게 한다.
React intentionally remounts your components in development to find bugs. In production, you would only see "console.log("...")" printed once.
When Strict Mode is on, React remounts every component once after mount (state and DOM are preserved). This helps you find Effects that need cleanup and exposes bugs like race conditions early.
race conditions (4번 문제 예시)
https://react.dev/learn/synchronizing-with-effects#challenges
👉 development Mode이고 Strict Mode가 켜져 있을 때 react는 mount된 후 다시 remout되게 된다. 이는 cleanup해야하는 코드를 찾거나 버그를 찾는데 유용하다.
사전
(출처: Chat GPT)
- synchronization
물체 또는 프로세스 간의 "synchronization(동기화)"은 서로의 상태나 동작을 조정하여 일관성을 유지하고 충돌을 방지하는 것을 의미합니다. 이는 여러 작업이 동시에 진행되는 상황에서 필요한 조치를 말합니다.
React에서의 "synchronization(동기화)"은 컴포넌트의 상태나 생명주기 변화에 따라 발생하는 작업들을 조정하는 것을 의미합니다.