by tylerFowler · 7y ago · 0 comments
Though I'll admit getting the relationship of state and effects caused by changes to that state can be more difficult to work out mentally, I think it results in a more complete understanding of what a component actually does.
A good mental model is that the second argument to useEffect defines which pieces of state that effect syncs with.
useEffect(() => {}, undefined) // Sync with all state
useEffect(() => {}, []) // Sync with no state
useEffect(() => {}, [a, b]) // Sync with `a` & `b`