Question · JavaScript and React course · Module 5: useEffect and Custom Hooks
Race Conditions in useEffect
How do you prevent race conditions when fetching data in useEffect (e.g., quickly switching between pages)?
Answer options
- Use a cancelled/ignore flag in the cleanup function to discard results from outdated requests
- Use setTimeout to delay each request by one second
- Disable strict mode in React
- Move the fetch to a class component
You can check the correct answer by solving this task in the CodeWorlds game.