Customer information

In the checkout form, we will add text fields to collect the customer name and email.

mern-marketplace/client/cart/Checkout.js:

<TextField id="name" label="Name" value={this.state.checkoutDetails.customer_name} onChange={this.handleCustomerChange('customer_name')}/><TextField id="email" type="email" label="Email" value={this.state.checkoutDetails.customer_email} onChange={this.handleCustomerChange('customer_email')}/><br/>      

When the user updates the values, the handleCustomerChange method will update the relevant details in the state:

handleCustomerChange = name => event => {    let checkoutDetails = this.state.checkoutDetails    checkoutDetails[name] = event.target.value || undefined this.setState({checkoutDetails: checkoutDetails}) ...

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.