'React-Native: debouncing async function with lodash
in my react-native app I update user settings using a slider, I don't want to make an axios call everytime a user slides an option so I want to use lodash debounce.
For some reason I'm getting the following error within my debounce function:
Expected a function
My code:
const handler = useCallback(_.debounce(editUserData, 2000), []);
const onSlideChange = (slideIndex) =>
{
setActiveSlide(slideIndex);
handler();
};
const editUserData = async () =>
{
setLoader(0);
try
{
setLoader(1);
let url = env.BASE_URL+'/api/users/update-user-settings';
let payload = { user_id:1 };
let response = await http.post(url, newPayload);
setLoader(2);
navigation.goBack();
}
catch(error)
{
setLoader(3);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
