Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
pcmaffey
on Nov 10, 2017
|
parent
|
context
|
favorite
| on:
Simple React Patterns
Protect the setStates in the callback with a conditional switch that gets flipped off in componentWillUnmount.
kshahkshah
on Nov 10, 2017
[–]
Not clear on what you're saying, pseudocode?
topgunsarg
on Nov 10, 2017
|
parent
[–]
In componentWillUnmount, set a var componentUnmounted true. In componentDidMount in the callback for the fetch, check for componentUnmounted before setting state for an error or whatever you want to do.
travmatt
on Nov 10, 2017
|
root
|
parent
[–]
Set a variable... set a property in the component state? Or set a static variable on the class?
pcmaffey
on Nov 10, 2017
|
root
|
parent
[–]
I use a static var on the class.
componentDidMount() { if (!this.unmounted) ... } componentWillUnmount() { this.unmounted = true }
fatso83
on Nov 11, 2017
|
root
|
parent
[–]
That's not a static car on the class. It's on the instance! A static class property would entail something like `Foo.unmounted = true` (a bad idea).
Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: