【发布时间】:2018-09-21 22:06:16
【问题描述】:
我以前可以正常工作,但现在我不知道发生了什么。我将 Next.js 用于 SSR,我的 Pay 元素如下所示:
class Pay extends React.Component {
constructor() {
super();
this.state = { stripe: null };
}
componentDidMount() {
console.log(window.Stripe)
this.setState({
stripe: window.Stripe('pk_test_123'),
});
}
render() {
console.log(this.state)
return (
<StripeProvider apiKey={this.state.stripe}>
<Elements>
<InjectedCheckoutForm />
</Elements>
</StripeProvider>
);
}
}
上面抛出错误:
请将“apiKey”或“stripe”传递给 StripeProvider。如果你是 使用 'stripe' 但还没有 Stripe 实例,传递 'null' 明确的。
我在这里感到困惑的是,事实上,窗口,也没有记录状态,因为页面抛出了 500 错误。 如果我删除 StripeProvider 组件,window.Stripe 会正常注销,并且 this.state 包含我的 Stripe 状态,所以我不明白它为什么会抛出错误。
【问题讨论】:
标签: reactjs next.js stripe-payments