2016-10-03 3 views
0

그래서 나는 네비게이션 바 있고 나는 그들이에 로그인 한 경우 사용자의 이름을 표시 할 나는이 경우 한 Statment가 : 문이 실행되는 경우React : get 요청에 어떻게 상태를 설정합니까?

var that= this; 
this.state = {name: null, signedIn: false} 
if (user){ 
     axios.get('https://apiendpoint/' + user.id) 
     .then(function (response) { 
      console.log(response); 
      that.state = {name: response.data.firstName, signedIn: true} 
      //this.setState({ showModal: false }); 
     }) 
     .catch(function (error) { 
      console.log(error); 
     }); 
     } 

을하지만, 상태 변수는하지 않습니다 점점지고있는 것 같아. var that =this이 상태 변수를 설정하지 못하거나이를 수행하는 더 좋은 방법이 있습니까?

답변

0

알아 냈어. 나는 this.state = {...}

보다는 that.setState({...});을 사용해야했다.
관련 문제