4 ms·
In componentWillUnmount, set a var componentUnmounted true. In componentDidMount in the callback for the fetch, check for componentUnmounted before setting stat
by topgunsarg 9y ago
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 9y agoSet a variable... set a property in the component state? Or set a static variable on the class?
- pcmaffey 9y agoI use a static var on the class. componentDidMount() { if (!this.unmounted) ... } componentWillUnmount() { this.unmounted = true }
- fatso83 9y agoThat'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).