I'm using multiple useEffect
hooks to perform the componentDidMount
and componentDidUpdate
functionalities, however, looks like when component loads, all my useEffect fires initially...
const testComp = () => {
const stateUserId = useSelector(state => { return state.userId; });
const [userId, setUserId] = useState(stateUserId);
const [active, setActive] = useState(false);
const [accountId, setAccountId] = useState();
useEffect(() => {
console.log('component did mount...');
}, [userId]);
useEffect(() => {
console.log('should trigger when userId changes...');
}, [userId]);
useEffect(() => {
console.log('should trigger when active changes...');
}, [active]);
useEffect(() => {
console.log('should trigger when accountId changes...');
}, [accounted]);
return (<div>...</div);
}
when my component mounts, I see all those console log there
component did mount...
should trigger when userId changes...
should trigger when active changes...
should trigger when accountId changes...
How could I only let my first useEffect
fires, but the other three fires when the dependency changes only?