gpt4 book ai didi

javascript - 如何修复React Native中的 '.then is not a function'

转载 作者:行者123 更新时间:2023-12-02 23:17:04 25 4
gpt4 key购买 nike

我在 native react 中遇到错误,在这段代码中显示“.then 不是函数”,我在 .then(()=>{this.manageAccess 中使用 .this ()})我能做什么?

或者告诉我是否有 .this 的替代品

export function signIn(data) {
const request = axios({
method:"POST",
url:SIGNIN,
data:{
email: data.email,
password: data.password,
returnSecureToken:true
},
headers:{
"Content-Type":"application/json"
}
}).then( response => {
return response.data
}).catch(e =>{
return false
});

return {
type: SIGN_USER,
payload: request
}
}

class LoginForm extends Component {

manageAccess = () => {
if(!this.props.User.userData.uid){
this.setState({hasErrors:true})
} else {
setTokens(this.props.User.userData,()=>{
this.setState({hasErrors:false});
this.props.navigation.navigate('Dashboard')

})
}
};

submitUserHandler = ()=>{
let isFromValid = true;
let formToSubmit= {};
if(isFromValid){
if(this.state.type === "Login"){
this.props.signIn(formToSubmit).then(()=>{
this.manageAccess()
})
}
}
};
}

最佳答案

您的 signIn() 函数返回一个对象,其中 request 对象位于 payload 属性中

尝试更改为

this.props.signIn(formToSubmit).payload.then(...

关于javascript - 如何修复React Native中的 '.then is not a function',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57125544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com