Building a Grocery List App with React

45 minutes
  • 4 Learning Objectives

About this Hands-on Lab

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.


<!DOCTYPE html>
<html lang="en">
    <!-- rest of head omitted -->
    <title>React App</title>
  <!-- body omitted -->
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.

Additional Resources

We've decided we'd like to be a little more organized when we go to the grocery store so we need to make fewer decisions. Noting what we need to buy in advance is good, but every shopping list application we've used is missing one key feature: quantities. In addition to the name of the item we need to buy, we also want to jot down how many we need so we have one fewer decision to make when we're in the bread aisle.

We've decided to build a React application to meet our needs, and here are the features we'd like our application to have:

  • A form for adding an item to the list including its name and quantity.
  • The shopping list displayed with the ability to check items off as we've put them in our shopping cart.

When we submit the form to add an item to the list, it should immediately show up and the form should be reset to an empty state so we can get right back to adding items.

Logging In

There are a couple of ways to get in and work with the code. One is to use the credentials provided in the hands-on lab overview page, log in with SSH, and use a text editor in the terminal.

The other is using VS Code in the browser. To go this route, it's necessary to navigate to the public IP address of the workstation server (provided in the hands-on lab overview page) on port 8080 (e.g. https://PUBLIC_IP:8080). Your password will be the same password that you'd use to connect over SSH.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?