я хочу получить данные (массив) из / {url}, и я попробовал этот код
// Fetch the list on first mount
componentDidMount() {
this.getList();
}
// Retrieves the list of items from the Express app
getList = () => {
fetch('/main')
.then(res => res.json())
.then(list => this.setState({ list }))
}
это работает нормально, но затем я решил переключиться на axios и попробовал буквально тот же код
// Fetch the list on first mount
componentDidMount() {
this.getList();
}
// Retrieves the list of items from the Express app
getList = () => {
axios.get('/main')
.then(res=> res.json())
.then(list => this.setState({list}))
}
но это не сработало и дало мне ошибку в этой строке: .then (res => res.json ()), поэтому я не знаю, в чем проблема, если кто-нибудь знает ключ, я буду рад, если выскажи мне