Giter Club home page Giter Club logo

shopping-list's Introduction

๐Ÿ›๏ธ Shopping List

A simple React app to create shopping list for your next store visit.

Demo

https://reacts-shopping-list.netlify.app/

Local Development Setup

Steps to run the site locally for development or curiosity

  1. Fork and clone the repository

    Follow these steps to create a fork of this repository and clone it to your local machine.

  2. Go to the project directory

  cd my-project
  1. Install dependencies
  npm install
  1. Start the server
  npm run start

shopping-list's People

Contributors

aishwarya-mali avatar

Stargazers

Anne Thorpe avatar

Watchers

James Cloos avatar  avatar

Forkers

msathyaanand

shopping-list's Issues

Added comments to the code for easy explanation

import { useState } from "react";

export default function App() {
// Initialize the state of the list of items to an empty array using the useState hook
const [items, setItems] = useState([])

// Add a new item to the list when the user submits the form
function handleAddItem(item) {
setItems(items => [...items, item])
}

// Remove an item from the list when the user clicks the delete button
function handleDeleteItem(id) {
setItems(items => [...items.filter(i => i.id !== id)])
}

// Clear the entire list when the user clicks the "Clear All" button
function handleClearAll() {
const deleteItems = window.confirm('Are you sure you wish to delete all items?')
if (deleteItems) setItems([])
}

// Render the different components of the application
return (





{items.length > 0 && Clear All}

);
}

// Render the header of the application
function Header() {
return (

๐Ÿ›๏ธ Shopping List


)
}

// Render the form for adding items to the list
function AddItem({ onAddItem }) {
const [item, setItem] = useState("")

// Add a new item to the list when the user submits the form
function handleSubmit(e) {
e.preventDefault()
if (!item) return
const newItem = {
item,
id: Date.now()
}
onAddItem(newItem)
setItem("")
}

// Render the form for adding items to the list
return (



<input type="text" placeholder="Enter Item" value={item} onChange={e => setItem(e.target.value)} />
Add Item


)
}

// Render the list of items and provide a button to delete each item
function Items({ items, onDeleteItem }) {
return (


    {items.map(i => (
  • {i.item} <button onClick={() => onDeleteItem(i.id)}>โŒ

  • ))}

)
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.