我的代码如下。我收到 undefined is not a function (evaluating '_this.storeAPIToken(responseJson.APIToken)') 错误
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 不为 null,当我控制台记录它时它具有值
最佳答案
从调用 this.storeAPIToken(responseJson.APIToken);
的行中删除 this.
。该行引用的 this 上下文与 storeAPIToken
的上下文不同。
关于javascript - undefined 不是 React Native 的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46130509/