Listing 4-3: Using components to reduce complexity
Cart
total: $
import React from 'react';
import CartItems from './CartItems';
import DisplayTotal from './DisplayTotal';
import CheckoutButton from './CheckoutButton';
import styles from './Cart.css.js';
function Cart(props){
return(
<div style={styles.cart}>
<h2>Cart</h2>
<CartItems items = {props.inCart} />
<DisplayTotal items = {props.inCart} />
<CheckoutButton />
</div>
);
}
export default Cart;
Download the examples, report issues, and ask/answer questions in the discussion area by visiting the book's github page. All of the code for the book is also available on codesandbox.io for you to play around with.
ReactJS Foundations is published by John Wiley and Sons, Inc and is available in paperback and eBook.