[TypeError: undefined не является объектом (оценка 'this.setState')] - PullRequest
0 голосов
/ 25 февраля 2020

У меня проблема с ReactNative и axe ios. Я хотел бы сохранить URL-адрес ответа в переменной состояния, но у меня есть эта проблема:

[TypeError: undefined is not an object (evaluating 'this.setState')]

Функция:

githubGetUrl = () => {
    axios({
      method: 'get',
      url: 'http://' +  global.IP_ADDRESS + ':8080/github/link'
    }).then(function(response) {
      this.setState({githuburl: response.data.LINK})
      console.log('Résultat [' + this.state.githuburl + ']')
    }).catch(function(error) {
      console.log(error)
    });
  }
}

Конструктор:

constructor (props) {
  super(props)
  this.state = {
    clicked: '',
    githuburl: ''
  }
}

Я уже ищу в Интернете, но не могу найти причину проблемы ...

Если кто-то может мне помочь, я буду признателен.

Спасибо

1 Ответ

1 голос
/ 26 февраля 2020

Вы можете попробовать использовать функцию стрелки в then

githubGetUrl = () => {
    axios({
      method: 'get',
      url: 'http://' +  global.IP_ADDRESS + ':8080/github/link'
    }).then((response) => {
      this.setState({githuburl: response.data.LINK})
      console.log('Résultat [' + this.state.githuburl + ']')
    }).catch(function(error) {
      console.log(error)
    });
  }
}
...