I want to fetch all of the custom taxonomies and show them on a page.
However when i pass them as Objects i can’t use .map for each of them. Do you know what would be the best approach to loop them? (see Screenshots)
Please note that currently the API is not working as i am taking some actions on the hosting, so you might not be able to reproduce it. It will be available from Monday again.
Apologies for the delay in getting back to you. I just cloned your repo and everything seems to be working okay. I’m guessing you fixed your issue since your last post?
The compile took a bit longer than usual, but this may be due to the assets that you’re downloading.
No worries at all.
Yes, regarding of looping through the categories, i fixed it.
However for getting the description from the taxonomies i wasn’t able to fix it with the resolution you provided.
When i try actions.source.fetch("/category/example", { force: true });, the script runs an unlimited number of requests and eventually crashes. (see one of my previous answers above)
Your problem regarding the infinite loop in the taxonomies seem to be that you are calling const TaxonomyData = actions.source.fetch('/cuisine'); inside of the body of the react component.
Calling fetch() will update the state, so when it finishes, it will re-render the GetTaxonomy component with new data, causing the actions.source.fetch('/cuisine') to be executed again, and again…
What you want to do is wrap the actions.source.fetch() with useEffect(), something like:
Thank you very much for explaining the Issue well and providing a solution for it.
It works perfect as you described it. Only instead of const taxonomy = state.source[data.type][data.id];
i must use const taxonomy = state.source[data.taxonomy][data.id];