Hands-on : Build a Grocery List App

Goal: Build a Grocery Wish List App

The React app with Vite for managing a grocery list is set up! Follow these steps:

  1. Project Initialization: Use the Vite template for React and install Bootstrap for styling.

  2. Component Structure: The app is modular, with separate components for each feature.

  3. Implementation Details: Each component handles specific functionality, ensuring maintainable code.

  4. Integration: All components come together in AppGrocery.jsx, the parent component, using state management.

Run npm run dev to see your grocery list application in action!

Step 1. Initialize the project

Run the following commands in your terminal to create a Vite React project and install Bootstrap for styling.

Step 2. Structure the src folder

Create the necessary folder structure for organizing the application components.

Step 3. Implement HeaderNav.jsx

  • This component displays the application header with a title.

  • Create HeaderNav.jsx file in src/components folder

Step 4. Implement GroceryInputForm.jsx

  • This component contains an input field and a button to add new grocery items.

  • Create GroceryInputForm.jsx file in src/components folder

Step 5. Implement GroceryList.jsx

  • This component displays a list of grocery items with toggle and delete functionalities.

  • Create GroceryList.jsx file in src/components folder

  • use icon style for delete button. For this, the delete button has been updated to use a Bootstrap icon (bi bi-trash) for a more polished and modern look. You need to install bootstrap-icons at terminal if not installed.

Step 6. Implement Footer.jsx

  • This component displays a summary of total items and the number bought.

  • Create Footer.jsx file in src/components folder

Step 7. Implement the parent component AppGrocery.jsx

  • This is the main component that integrates all child components and manages the application state.

  • Create AppGrocery.jsx in src folder

  • import Ass.css style

Step 8. Update main.jsx to render AppGrocery

  • This step ensures the main application component is rendered to the DOM.

//Step 9. Run the application

Use the following command to start the development server and view the app in the browser.

Run npm run dev to see your grocery list application in action!

Summing Up

  • Forms

    • Set up

    • Handling onSubmit

    • Multi-input field form

  • Controlled Element

  • Built a Grocery List Web App

    • Lifted state up to the parent component

Last updated