Put in order · JavaScript and React course · Module 11: Data Fetching and APIs
AbortController Lifecycle in useEffect
Arrange the order of events when the user quickly changes planetId from 1 to 2 (with AbortController):
Items to put in order
- fetch_2 completes successfully and updates state
- controller_1.abort() cancels fetch_1 (AbortError)
- planetId changes to 2 - React calls cleanup
- useEffect creates controller_2 and sends fetch for planetId=2
- useEffect creates controller_1 and sends fetch for planetId=1
You can check the correct answer by solving this task in the CodeWorlds game.