[英]How to use the info from a component on another component
I am trying to create a payment system in my application.我正在尝试在我的应用程序中创建一个支付系统。
I have a payment form(paymentForm.js) and it contains the payment information(cardnumber, cvv, expiry...).我有一个付款表格(paymentForm.js),它包含付款信息(卡号、cvv、到期...)。 Is there any way that I can get these information on another component(checkoutPage.js)?
有什么方法可以让我在另一个组件(checkoutPage.js)上获取这些信息? Do you have any advice?
你有什么建议吗?
Below is my paymentForm.js:下面是我的 paymentForm.js:
export default class PaymentForm extends React.Component {
state = {
cvv: '',
expiry: '',
focus: '',
name: '',
number: '',
};
handleInputFocus = (e) => {
this.setState({ focus: e.target.name });
}
handleInputChange = (e) => {
const { name, value } = e.target;
this.setState({ [name]: value });
}
render() {
return (
<View>
<Cards id="PaymentForm"
cvc={this.state.cvc}
expiry={this.state.expiry}
focused={this.state.focus}
name={this.state.name}
number={this.state.number}
/>
<form style={{}}>
<input
type="tel"
name="number"
placeholder="Card Details"
maxLength="16"
preview='true'
onChange={this.handleInputChange}
onFocus={this.handleInputFocus}
/>
<br/>
<input
type="text"
name="name"
placeholder="Holder Name"
onChange={this.handleInputChange}
onFocus={this.handleInputFocus}
/>
<br/>
<input
type="tel"
name="expiry"
placeholder="Expiration"
maxLength="4"
onChange={this.handleInputChange}
onFocus={this.handleInputFocus}
/>
<br/>
<input
type="tel"
name="cvc"
placeholder="CVV"
maxLength="5"
onChange={this.handleInputChange}
onFocus={this.handleInputFocus}
/>
<br/>
<input
type="tel"
name="zipcode"
placeholder="ZIP Code"
maxLength="5"
onChange={this.handleInputChange}
onFocus={this.handleInputFocus}
/>
</form>
</View>
);
}
}
You should create a file CheckOut.js and give card information via props.您应该创建一个文件 CheckOut.js 并通过道具提供卡片信息。 There is also another way to do it by creating a class named 'Checkout' and creating static methods inside.
还有另一种方法可以通过创建名为“Checkout”的 class 并在内部创建 static 方法来实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.