This post explains the purpose of useEffect in React, how side effects are handled in class-based components, and how to fix the stale closure problem with useEffect.
Table of contents
What is an “effect” anyway?Side Effects in ReactThen Came React HooksUseEffect and Previous State: Where things fall apartWhat is a “ref”, and how do you use one?Using Refs to avoid Stale ClosuresState Versus RefsParting Thoughts2 Comments
Sort: