10. Functional Programming with JavaScript
Activity 15: onCheckout Callback Prop
Solution
- Change the current directory to
Lesson10
and runnpm install
if you haven't done so in this directory before.npm install
downloads the dependencies that are required in order to run this activity (React and Parcel). - Run
parcel serve activity-on-checkout-prop-start.html
and then executenpm run Activity15
. You will see the application starting up, as follows:Figure 10.42: Output after running the start html script
- Go to
http://localhost:1234
(or whichever URL the start script output). You should see the following HTML page:Figure 10.43: Initial application in the browser
- The
onClick
of the Proceed to checkout can be implemented as follows:Â Â render() { Â Â Â Â return ( Â Â Â Â Â Â <div> Â Â Â Â Â Â Â Â <p>You have {this.state.items.length} items in your basket</p> &...