diff --git a/src/components/App.js b/src/components/App.js index 6b15d49f8..79952ac74 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -1,18 +1,24 @@ -import React from "react"; +import React, { useState } from "react"; + import ShoppingList from "./ShoppingList"; import itemData from "../data/items"; function App() { + const [isOn, setIsOn] = useState(false); + + function handleClick() { + setIsOn((isOn) => !isOn); + } // replace 'false' with a state variable that can be toggled between true and false // this will be used for the Dark Mode Toggle feature - const appClass = false ? "App dark" : "App light" + const appClass = isOn ? "App dark" : "App light"; return (

Shopster

- +
diff --git a/src/components/Item.js b/src/components/Item.js index b833ecf8e..2f4aaf48f 100644 --- a/src/components/Item.js +++ b/src/components/Item.js @@ -1,11 +1,19 @@ -import React from "react"; +import React, { useState } from "react"; function Item({ name, category }) { + const [isInCart, setIsInCart] = useState(false); + + function handleClick() { + setIsInCart((isInCart) => !isInCart); + } + return ( -
  • +
  • {name} {category} - +
  • ); } diff --git a/src/components/ShoppingList.js b/src/components/ShoppingList.js index a48d82615..6de91f786 100644 --- a/src/components/ShoppingList.js +++ b/src/components/ShoppingList.js @@ -1,11 +1,23 @@ -import React from "react"; +import React, { useState } from "react"; + import Item from "./Item"; function ShoppingList({ items }) { + const [displayItems, setDisplayItems] = useState(items); + + function handleChange(event) { + setDisplayItems( + items.filter((item) => { + if (event.target.value === "All") return true; + else return item.category === event.target.value; + }) + ); + } + return (
    - @@ -13,7 +25,7 @@ function ShoppingList({ items }) {