useEffect(() => {
getTodo()
}, [getTodo])
const getTodo = useCallback(async () => {
try {
await axios.get('/api/todo', {
headers: {
'Content-Type': 'application/json'
},
params: {userId}
})
.then((response) => {
setTodos(response.data)
})
} catch (error) {
console.log(error)
}
}, [userId, setTodos])
let cleanupFunction = false;
return () => cleanupFunction = true;
useEffect(() => {
let stopGettingAfterUnmount = false;
const getTodo = async () => {
await axios
.get("/api/todo", {
headers: {
"Content-Type": "application/json",
},
params: { userId },
})
.then((response) => {
if (stopGettingAfterUnmount) return;
setTodos(response.data);
});
};
getTodo();
return () => {
stopGettingAfterUnmount = true;
};
}, [userId]);