DEV Community

Stop Race Conditions: React AbortControllers ⚡ (opens in new tab)

Discussed on DEV

The Unmounted Component Trap In highly interactive dashboards at Smart Tech Devs, users navigate quickly. Imagine a user clicks a "Generate Heavy Report" button, which fires an API request that takes 4 seconds to resolve. After 2 seconds, the user gets bored, clicks the "Back" button, and navigates away. The React component unmounts. However, the browser's HTTP request is still in-flight! Two seconds later, the promise resolves, and the callback attempts to execute setReportData(data) on a co...

Read the original article
Sign in to keep reading the full article.

Keyboard Shortcuts

Navigation

Next / previous post
j/k
Open post
oorEnter
Preview post
v

Post Actions

Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Save / unsave
s

Recommendations

Add interest / feed
Enter
Not interested
x

Go to

Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Discover
gb
Search
/

General

Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help