What are race conditions in effects and how do you prevent them?
Model answer
If a dependency changes quickly (for example a search term), several requests are in flight, and an older one may finish last and overwrite newer data. Prevent it by aborting the previous request in cleanup using AbortController, or by setting let ignore = false and setting it to true in cleanup, then only calling setState when not ignored.
Learn this topic
React useEffect Explained: Side Effects, Dependencies and Cleanup in the course React.js Full Course: Beginner to Advanced.
Sign in to add your own answer.