Skip to content
Advertisement

Why does data from my api only display once and when I refresh the page it gives an error

Im working on a project that displays a random food title and the image of that food. Im having trouble figuring out why the data displays on the page only once and once I refresh the page, it gives an error of “Uncaught TypeError: recipeList.recipes is undefined”.

This is my home.js

JavaScript

and this is my Recipe.js component

JavaScript

Advertisement

Answer

you should verify if you data food is not empty or null, here an example:

JavaScript

first at all you need to load the datas in useeffect

JavaScript

you are loading empty data when you reload the page

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement