2016-10-14 8 views
0

loginUser()이라는 함수 내에서 두 개의 메서드 호출이 있습니다. 첫 번째는 userInfo를 전달하고 API 요청을 한 다음 메소드를 실행하여 로그인 텍스트 필드를 비 웁니다.ReactJS : "정의되지 않은"속성을 읽을 수 없습니다.

그러나 오류 Cannot read property 'then' of undefined이 표시됩니다. 무엇이 문제 일 수 있습니까?

코드 :

_loginUser() { 
    this.props.loggingInUser(this.props.userInfo) //Would like to finish this first before moving onto calling this.props.emptyLoginTextFields() 
    .then(() => { //Here is where the error is occurring 
     this.props.emptyLoginTextFields() 
    }) 
    } 

사전에 감사합니다!

+0

'props' 또는'loggingInUser()'와 같이 소리가 나지 않습니다.'props' 나 디버깅을 로그 아웃하고 둘 다 정의되도록 할 수 있습니까? –

+1

'loggingInUser'는 아무것도 반환하지 않을 수도 있습니다 ... – ctrlplusb

+0

loggingInUser 함수는 어떻게 보이나요? – StackOverMySoul

답변

1

loggingInUser 함수 내부의 ajax 호출에서 약속을 되 돌리는 것에주의하십시오. return 문이 없으므로 기본 반환 값은 JS의 경우 undefined입니다.

예 : 당신은 결과를 반환 "Axios의"같은 약속 관리자를 반환해야

function loggingInUser(credentials) { 
    return fetch('/foo/bar'); 
} 
4

,

예 :

에 초점 "axios.all을 반환 "

getPlayersInfo: function (players) { 
    return axios.all(players.map((username) => { 
     return getUserInfo(username) 

    })) 
     .then((info) => { 
     return info.map((user) => { 
      return user.data; 
     }); 
    }) 
     .catch(function (err) { 
     console.warn("error in getPlayerInfo",err); 
    }); 
} 

};

+0

감사합니다, 다른 응답에서 "반환"볼 수 있지만 당신의 대답은 내 하루를 저장합니다. –

관련 문제