Answer the question
In order to leave comments, you need to log in
Problem with useEffect?
I have a request to api when changing 3 parameters in the state, respectively, it is written something like this
useEffect(() => {тут запрос}, [param1, param2, param3])
Answer the question
In order to leave comments, you need to log in
Use an object.
const [params, setParams] = useState({
name: "John",
email: "[email protected]",
age: 30
});
Add to the isFirstRender state, for example...
const [isFirstRender, setNotFirstRender] = useState(true);
useEffect(() => {
if(isFirstRender) {
// тут запрос
setNotFirstRender(false);
}
}, [param1, param2, param3, isFirstRender]);
useEffect(() => {
Promise1.then(() => { // первый параметр
Promise2.then(() => { // второй
Promise3.then(() => { // третий
}
}
});
}, [param1, param2, param3]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question