DEV Community

Discussion on: Correctly handling async/await in React components

Collapse
 
mousticke profile image
Akim (mousticke.eth) @Colossos

Nice post. It's really helpful.
I'm just starting to learn the hooks system.
I know I can just google it but why would you use ref instead of state for componentIsMounted ? What is the purpose ?

Collapse
 
jamesthomson profile image
James Thomson

Ref's don't cause the component to re-render so you can update the value without side effects - in this case, the side effect being an unwanted state update (due to the resolving async call) that occurs after the component has actually been in an unmounted.