Reputation: 5113
const [selected, setSelected] = useState(1);
useEffect(() => {}, [selected])
Since selected is just 1, why isn't the useEffect
above equivalent to:
useEffect(() => {}, [1])
Upvotes: 0
Views: 429
Reputation: 726
Well, in the first example, when selected
changes the effect re-runs. In your second example, you've put a hard-coded value in the deps array (that's never going to change), so the effect will never run again after the first component mount.
So to answer your question:
selected
state to change at some point, when that happens re-run the effect.Upvotes: 2