Hello,
For wordpress im busy with making a component who reads all categories.
So far I have this :
const [categories, setCategories] = useState([]);
const [chosenCategory, setChosenCategory] = useState(0)
const [posts, setPosts\] = useState([]);
useEffect(() => {
async function fetchCategories() {
const queryParams = { _fields: [‘name’, ‘id’] };
apiFetch({ path: addQueryArgs(‘/wp/v2/categories’, queryParams) }).then((response) => {
setCategories(response).catch((error) => {console.log(error)});
});
}
fetchCategories();
}, []);
but when I run this I see a message that setCategories is undefined.
Can someone explain why this happens and how to solve it
[ad_2]