I have a json file call data.json such as ( I use React.js):
[{"id": 1,"title": "Child Bride"},
{"id": 2, "title": "Last Time I Committed Suicide, The"},
{"id": 3, "title": "Jerry Seinfeld: 'I'm Telling You for the Last Time'"},
{"id": 4, "title": "Youth Without Youth"},
{"id": 5, "title": "Happy Here and Now"},
{"id": 6, "title": "Wedding in Blood (Noces rouges, Les)"},
{"id": 7, "title": "Vampire in Venice (Nosferatu a Venezia) (Nosferatu in Venice)"},
{"id": 8, "title": "Monty Python's The Meaning of Life"},
{"id": 9, "title": "Awakening, The"},
{"id": 10, "title": "Trip, The"}]
Im my componentDidMount I have the below:
fetch('./data/data.json')
.then((response) => response.json())
.then((findresponse)=>{
console.log(findresponse.title)
this.setState({
data:findresponse.title,
})
})
}
and in my render:
<ul>
<li> {this.state.title}</li>;
</ul>
I would like to list all the title from my json file,
Otherwise it says that .then((response) => response.json()) is an anonymous function . . .
How to fix this ? I'm a bit confused
many thanks
this.setState({ data: findresponse });and then in your render{this.state.data.map(x => x.title).join(',')}