exercise 1.6

This commit is contained in:
Anish Lakhwara 2023-05-15 21:14:50 +10:00
parent c72d4615d0
commit 711764b874

View file

@ -1,46 +1,50 @@
import { useState } from 'react'
const Display = ({ counter }) => {
const Stats = ({ positive, neutral, negative }) => {
return (
<div>{counter}</div>
<>
<h2> Results </h2>
<p> Positive: {positive} </p>
<p> Neutral: {neutral} </p>
<p> Negative: {negative} </p>
</>
)
}
const Button = ({ handleClick, text }) => {
const Button = ({ handler, text }) => {
return (
<button onClick={handleClick}>
<button onClick={handler}>
{text}
</button>
)
}
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 (
<div>
<Display counter={counter} />
<Button handleClick={increaseByOne} text="plus" />
<Button handleClick={setToZero} text="zero" />
<Button handleClick={decreaseByOne} text="minus" />
<h2> Feedback </h2>
<Button handler={incPositive} text="positive" />
<Button handler={incNeutral} text="neutral" />
<Button handler={incNegative} text="negative" />
<Stats positive={good} negative={bad} neutral={neutral} />
</div>
)
}
export default App