If we want to restrict useEffect
to run only when the component mounts, we can add second parameter of useEffect
with []
.
useEffect(() => {
// ...
}, []);
But how can we make useEffect
to run only when the moment when the component is updated except initial mount?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…