I have an Express API that sends a JSON object. This object has a property that is an array of objects. One of the properties in those objects is ‘title’.
How would I use fetch to set the state with this JSON object, and display that title property from the state in a JSX element?
In this component, if I change that h1 to some simple text (like “Hello world”) it runs error free - that console.log works, displaying an object as I expect in the console. I don’t understand why I’m unable to access this.state.ideas[0].title, though. It says it is undefined.
This will conditionally render this.state.ideas[0].title only if this.state.ideas[0] has a value which is not falsy. So as long as this.state.ideas[0] is an object, it’s title will be rendered.