From 711764b874c3dcc4f83203e19272ebd36913c90a Mon Sep 17 00:00:00 2001 From: Anish Lakhwara Date: Mon, 15 May 2023 21:14:50 +1000 Subject: [PATCH] exercise 1.6 --- part1/src/App.js | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/part1/src/App.js b/part1/src/App.js index edc4436..ea413aa 100644 --- a/part1/src/App.js +++ b/part1/src/App.js @@ -1,46 +1,50 @@ import { useState } from 'react' -const Display = ({ counter }) => { +const Stats = ({ positive, neutral, negative }) => { return ( -
{counter}
+ <> +

Results

+

Positive: {positive}

+

Neutral: {neutral}

+

Negative: {negative}

+ ) } -const Button = ({ handleClick, text }) => { +const Button = ({ handler, text }) => { return ( - ) } const App = () => { - const [counter, setCounter] = useState(0) - console.log('rendering with counter value', counter) - const increaseByOne = () => { - console.log('increasing, value before', counter) - setCounter(counter + 1) + const [good, setGood] = useState(0) + const [neutral, setNeutral] = useState(0) + const [bad, setBad] = useState(0) + + const incPositive = () => { + setGood(good + 1) } - const decreaseByOne = () => { - console.log('decreasing, value before', counter) - setCounter(counter - 1) + const incNegative = () => { + setBad(bad + 1) } - const setToZero = () => { - console.log('resetting to zero, value before', counter) - setCounter(0) + const incNeutral = () => { + setNeutral(neutral + 1) } return (
- -
) - } export default App