這裏是我的行動的創建者:如何在提交表單後反應原生?
export const signInByPhone = ({ phone })=>{
console.log('All props : ', this.props); // no props are coming. ??
return (dispatch) => {
fetch(`${API_URL}`, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
phone_no : phone
})
})
.then((res) =>res.json())
.then((jsonRes) =>{
if (jsonRes.code === 200) {
console.log('json response code1 : ', jsonRes);
// go to verification screen
generatOTPSuccess(dispatch,jsonRes);
}
else { // reset otp sending screen
console.log('json response code2 : ', jsonRes);
}
})
.catch(res => generatOTPFail(dispatch, res));
};
}
的輔助方法:
const generatOTPSuccess = (dispatch, res) =>{
dispatch({
type: 'OTP_GENERATE_SUCCESS',
payload: res
});
this.props.navigation.navigate('OtpVerify');
// Error : payload: TypeError: Cannot read property 'navigation' of
undefined at generatOTPSuccess
}
我想達到的目標,一旦成功OTP生成,它應該定位到VerifyScreen。 我無法做到。你們有誰可以說可能的方式?
在按一下按鈕,我已經通過了以下內容:
onButtonPress(){
const {phone}=this.props;
console.log(phone, " : this.props : ",this.props); // all props r coming
this.props.signInByPhone({ phone });
}
根據錯誤信息你無法得到this.props。你能控制this.props並檢查它是否給出了未定義? –