Skip to content
Advertisement

TypeError: Cannot read property ‘title’ of undefined Reactjs

I dont know why i have this error!! At first time i dont have any error and its work But when i refresh the page i have this error: TypeError: Cannot read property ‘title’ of undefined or TypeError: Cannot read property ‘image’ of undefined

JavaScript

Content.jsx :

JavaScript

Advertisement

Answer

The issue is here:

JavaScript

here post object will get data from axios call and it will take some time to fetch the data that means on initial render title will not be there. So you have to put some check and access that key only when it is available.

Try something like:

JavaScript

Or you can also try conditional rendering

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