why is setCategories is undefined

[ad_1]

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]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer