fullstack-open/part1/src/App.js
Anish Lakhwara 711764b874 exercise 1.6
2023-05-15 21:14:50 +10:00

51 lines
932 B
JavaScript

import { useState } from 'react'
const Stats = ({ positive, neutral, negative }) => {
return (
<>
<h2> Results </h2>
<p> Positive: {positive} </p>
<p> Neutral: {neutral} </p>
<p> Negative: {negative} </p>
</>
)
}
const Button = ({ handler, text }) => {
return (
<button onClick={handler}>
{text}
</button>
)
}
const App = () => {
const [good, setGood] = useState(0)
const [neutral, setNeutral] = useState(0)
const [bad, setBad] = useState(0)
const incPositive = () => {
setGood(good + 1)
}
const incNegative = () => {
setBad(bad + 1)
}
const incNeutral = () => {
setNeutral(neutral + 1)
}
return (
<div>
<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