Specifying Dependencies Of A useEffect Hook
const apiCall = (opts) => Promise.resolve(opts);
const [param1, param2, param3] = [1,2,3];
useEffect(() => {
const handleApiCall = async () => {
apiCall({ param1, param2, param3 })
.then((data) => {
// do something with the data
})
.catch((error) => {
// do something with the error
});
}
handleApiCall();
}, [param1, param2, param3]);Last updated