Answer the question
In order to leave comments, you need to log in
How to properly combine debounce and cancel token?
There is an option with cancel token that works:
useEffect(() => {
const asyncEnrollment = async () => {
const data = { userId, filter };
setLoading(true);
await initialEnrollment(dispatch, data);
setLoading(false);
};
asyncEnrollment();
}, [dispatch, userId, filter]);
const loadEnrollment = useRef(
debounce(async (data) => {
setLoading(true);
await initialEnrollment(dispatch, data);
setLoading(false);
}, 4000)
);
useEffect(() => {
const data = { userId, filter };
loadEnrollment.current(data);
}, [userId, filter]);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question