I am forcing below code to run through the catch
block where it sets getFoodCategoriesFailed
to true
and after that when it goes to finally
block it still shows getFoodCategoriesFailed
as false
which is its initial value. Can someone point it out what I am doing wrong and help me fix it.
const [getFoodCategoriesFailed, setGetFoodCategoriesFailed] = useState(false);
const getCategories = async (url) => {
const { request } = await requestor.get({ url });
request.then((response) => {
setFoodCategories(response);
setGetFoodCategoriesFailed(false);
}).catch(() => {
setFoodCategories(undefined);
setGetFoodCategoriesFailed(true);
}).finally(() => {
onFoodCategoriesRetrieved(getFoodCategoriesFailed, foodCategories?.food_categories);
});
};
useEffect(() => {
const url = "xyz";
getCategories(url);
}, [foodCategories]);