diff --git a/src/components/App.js b/src/components/App.js index 6b15d49f8..da5cf63c5 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -1,18 +1,19 @@ -import React from "react"; +import React, { useState } from "react"; import ShoppingList from "./ShoppingList"; import itemData from "../data/items"; function App() { - - // 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 [count, setCount] = useState(false) + const appClass = count ? "App dark" : "App light" + const buttonText = count ? 'Dark Mode' : 'Light Mode' return (

Shopster

- +
diff --git a/src/components/Item.js b/src/components/Item.js index b833ecf8e..78b64c037 100644 --- a/src/components/Item.js +++ b/src/components/Item.js @@ -1,11 +1,16 @@ -import React from "react"; +import React, { useState } from "react"; function Item({ name, category }) { + const [count, setCount] = useState(false) + const updateClass = count ? 'in-cart' : '' + const updateButtonText = count ? 'Remove From Cart' : 'Add to Cart' return ( -
  • +
  • {name} {category} - +
  • ); } diff --git a/src/components/ShoppingList.js b/src/components/ShoppingList.js index a48d82615..e694eb024 100644 --- a/src/components/ShoppingList.js +++ b/src/components/ShoppingList.js @@ -1,11 +1,15 @@ -import React from "react"; +import React, { useState } from "react"; import Item from "./Item"; function ShoppingList({ items }) { + + const [count, setCount] = useState('All') + const filterByCategory = count === 'All' ? items : items.filter(item => item.category === count) + return (
    - setCount(event.target.value)} name="filter"> @@ -13,9 +17,9 @@ function ShoppingList({ items }) {
    );