React is one of the most popular front-end web development frameworks in the world and something worth knowing a little about. It provides a declarative and composable interface to make building user interfaces with complex interactions more manageable. In this hands-on lab, we’ll go through building a simple grocery shopping list application from start to finish.
To feel comfortable completing this lab, you’ll need to know how to do the following:
– Create a new React application.
– Utilize state and props within React components.
– Handle browser events using React components.
If you’re currently unsure of how to perform any of these actions, consider taking the short **Expanding Your JS Skills with React** course to get up to speed.
Successfully complete this lab by achieving the following learning objectives:
- Create the `groceries` React Application
Generate a new React application called
groceriesso that we can build the grocery shopping list application.
Optional: Add Bulma for Styling
In order to follow along with the styling used in the example solution for this hands-on lab, you’ll need bulma.
<!DOCTYPE html> <html lang="en"> <head> <!-- rest of head omitted --> <title>React App</title> <link rel="stylesheet" href="https://email@example.com/css/bulma.min.css" /> <script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js" ></script> </head> <!-- body omitted --> </html>
- Display a New Item Form and the Grocery Items
The goal of this application is to act as a checklist of groceries that need to be purchased including the grocery item names and the quantity of each. To begin, we’ll want to modify our
Appcomponent to display a form that allows us to add a new grocery item and display the items already on our list.
- Add the Ability to Add a New Grocery Item
Write the necessary event handling function(s) to allow someone to submit the new grocery item form and have the information added to the application’s state. It should also be displayed to the screen.
- Add the Ability to Check Off a Grocery Item
Modify the application so that the user can click the checkbox of a grocery item and have it toggle the
purchasedstate of the grocery item in the application’s state.