【发布时间】:2019-09-07 21:11:22
【问题描述】:
我在 react-native 中使用条带库,我在 console.log 中成功获取数据,但是如果成功,或者如果它有任何错误,我想重定向到另一个页面,然后显示在页面上。我试图重定向到另一个页面,但即使它有错误,它也会重定向,我不知道该怎么做。我试过这样做..
这是我的代码。
payme() {
const apiKey = '<api_key>';
const client = new Stripe(apiKey);
client.createToken({
number: this.state.number,
exp_month: this.state.expmonth,
exp_year: this.state.expyear,
cvc: this.state.cvc,
}).then((x) => {
let successmsg = x;
NavigationService.navigate('LoginPage');
}).catch((e) => {
console.log(e);
})
}
render() {
return (
<Text>{this.successmsg}</Text>
)
}
谁能帮助我了解如何显示错误以及如何仅在成功时重定向到其他页面。
【问题讨论】:
-
这是哪里。 successmsg() ??
-
使用
this.setState({ response: x })并使用渲染函数中的状态{this.state.response}
标签: reactjs api react-native fetch stripe-payments