2017-09-09 5 views
0

내 코드는 다음과 같습니다. I는 정의는 (') _this.storeAPIToken (responseJson.APIToken'평가) 함수 오류없는 얻을undefined is not a function 네이티브 반응

async function storeAPIToken(APIToken) { 
    try { 
     await AsyncStorage.setItem('@auth:APIToken', APIToken); 
    } catch (error) { 
     console.log("STORE API", error); 
    } 
} 


const verifyOTPResponse = (dispatch, responseJson) => { 
    console.log("checkOTPAPIStatus", responseJson.status); 
    if (responseJson.status == "OK") { 
     console.log("verifyOTPEntered OK"); 

     console.log('Token', responseJson.APIToken); 
     this.storeAPIToken(responseJson.APIToken); 

     firebase.auth().signInWithCustomToken(responseJson.token).then(() => { 
      console.log("Login successfulx"); 

      dispatch({ 
       type: types.LOGIN_SUCCESS, 
       payload: 1 
      }); 

     }).catch(function(error) { 
      var errorCode = error.code; 
      var errorMessage = error.message; 

      dispatch({ 
       type: types.LOGIN_FAIL, 
       payload: 0 
      }); 

     }); 
    } else { 
     dispatch({ 
      type: types.OTP_VERIFICATION_FAIL, 
      payload: loginStatus 
     }); 

responseJson.APIToken는 I 콘솔 그것을

+0

오류는 '_this.storeAPIToken'에 있습니다. – Dekel

+0

'verifyOTPResponse'에는'storeAPIToken' 기능이 없습니다. 'this '를 사용하는 것은 잘못된 것입니다. 'this'를 제거하고 다시 시도하십시오 – bennygenel

+0

오류가'this.storeAPIToken'이'undefined '라는 사실을 언급하고있는 것 같습니다 - 아마도이 함수를 호출 할 때'this.'는 필요 없습니다. –

답변

1
를 기록한 때의 값을 갖는 널 아니다

this.storeAPIToken(responseJson.APIToken);을 호출하는 줄에서 this.을 제거하십시오. 이 줄을 참조하는이 컨텍스트가 1과 다릅니다. storeAPIToken.

관련 문제