Re:Simple React Patterns
by pcmaffey on Friday November 10, 2017 @09:26AM
(#15670038)
Protect the setStates in the callback with a conditional switch that gets flipped off in componentWillUnmount.
[ Parent
| on HN ]
Re:Simple React Patterns
by whistlerbrk on Friday November 10, 2017 @11:05AM
(#15670774)
Not clear on what you're saying, pseudocode?
Re:Simple React Patterns
by topgunsarg on Friday November 10, 2017 @11:10AM
(#15670820)
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.
Set a variable... set a property in the component state? Or set a static variable on the class?
I use a static var on the class.
componentDidMount() {
if (!this.unmounted) ...
}
componentWillUnmount() {
this.unmounted = true
}