18 lines
587 B
JavaScript
18 lines
587 B
JavaScript
import { useQuery } from '@tanstack/react-query';
|
|
|
|
export const useRecipeNutrition = (recipeId) => {
|
|
return useQuery({
|
|
queryKey: ['recipeNutrition', recipeId],
|
|
queryFn: async () => {
|
|
const response = await fetch(
|
|
`https://api.spoonacular.com/recipes/${recipeId}/nutritionWidget.json?apiKey=a2f1ea26b02d4919b35c7152b5ebac6d`
|
|
);
|
|
if (!response.ok) {
|
|
throw new Error("Failed to fetch nutrition data");
|
|
}
|
|
return response.json();
|
|
},
|
|
enabled: !!recipeId,
|
|
});
|
|
};
|