внешняя функция не принимает this.setState или this.state

Регулярное выражение для uuid:

[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
0
задан user3450590 4 March 2019 в 11:26
поделиться

2 ответа

Ваш ответ на обещание не разделяет область действия this, поэтому используйте функцию стрелки внутри отклика then ...


  postdata_fire(){
    Postdata('http://localhost:3000/places').then((result) =>{
      console.log("result::",result);
      this.setState({result:'sdujoij'})
    })

    this.setState({hits:'yahittsss'})
    console.log("hits:::",this.state.hits); 
  }
0
ответ дан sathish kumar 4 March 2019 в 11:26
поделиться

Вам потребуется рефакторинг postdata_fire следующим образом:

postdata_fire() {
 Postdata('http://localhost:3000/places').then(result => {
   console.log("result:: %j",result);
   this.setState({result_: result});
 });
 ...
}

и Postdata тоже:

export const Postdata = (url='') => {
  return fetch(url).then(response => {
    console.log("response.json()::",response)
    return response.json();
  });
}

0
ответ дан North Halcyon 4 March 2019 в 11:26
поделиться
Другие вопросы по тегам:

Похожие вопросы: