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.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Create the Groceries React Application
Generate a new React application called
groceries
so 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.
public/index.html
<!DOCTYPE html> <html lang="en"> <head> <!-- rest of head omitted --> <title>React App</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.0/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
App
component 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
purchased
state of the grocery item in the application’s state.