function RecipesList() {
//use effect to
useEffect(() => {
const getRecipesList = async () => {
const response = await fetch("http://localhost:4000/recipe/allrecipes", {
method: "GET",
});
const json = await response.json();
if (response.ok) {
setData(json);
const allCategories = [
"all",
...new Set(data.map((item) => item.category)),
];
setCategories(allCategories);
}
};
getRecipesList();
//get all categories from data
}, []);
}
Want to populate categories array base on data array
Data array is populated from databse