if i use useEffect hook as useEffect(() => {…},[depen1, depen2]). will the useEffect run if changes happen in one of the dependency ?
will it run ? or do i need to another useEffect ?
//GET API NORMAL FOR FIRST LOAD
useEffect(() => {
axiosGetCall();
// eslint-disable-next-line
}, []);
//GET API IF DID CHANGE
useEffect(() => {
if (didChange === true) {
// if there is something in details do this
if (details.email === false) {
axiosGetCall();
} else {
setSearch(true);
axiosGetCall();
}
}
// eslint-disable-next-line
}, [didChange]);
//GET API IF DID Search
useEffect(() => {
if (search === true) {
axiosGetCall();
}
// eslint-disable-next-line
}, [search]);
//GET API WHEN PAGE CHANGES
useEffect(() => {
if (pageChange === true) {
setValues({ ...values, success: "", error: "" });
// if there is something in details do this
if (details.email === false) {
axiosGetCall();
} else {
setSearch(true);
axiosGetCall();
}
}
// eslint-disable-next-line
}, [pageChange]);
>Solution :
useEffect runs if any of the dependencies change. See https://reactjs.org/docs/hooks-effect.html.