diff options
Diffstat (limited to 'part1/anecdotes/src/App.js')
-rw-r--r-- | part1/anecdotes/src/App.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/part1/anecdotes/src/App.js b/part1/anecdotes/src/App.js new file mode 100644 index 0000000..efb32a2 --- /dev/null +++ b/part1/anecdotes/src/App.js @@ -0,0 +1,37 @@ +import { useState } from 'react' + +const Button = (props) => { + return ( + <button onClick={props.onclick}> + {props.text} + </button> + ) +} + +const Display = (props) => { + return ( + <p>{props.text} {props.count}</p> + ) +} + +const App = () => { + // save clicks of each button to its own state + const [good, setGood] = useState(0) + const [neutral, setNeutral] = useState(0) + const [bad, setBad] = useState(0) + + return ( + <div> + <h1>give feedback</h1> + <Button onclick={() => setGood(good + 1)} text="good" /> + <Button onclick={() => setNeutral(neutral + 1)} text="neutral" /> + <Button onclick={() => setBad(bad + 1)} text="bad" /> + <h2>statistics</h2> + <Display text="good" count={good} /> + <Display text="neutral" count={neutral} /> + <Display text="bad" count={bad} /> + </div> + ) +} + +export default App |