aboutsummaryrefslogtreecommitdiff
path: root/part1/unicafe/src/App.js
diff options
context:
space:
mode:
authorIbrahim Mkusa <ibrahimmkusa@gmail.com>2023-04-25 22:29:03 -0400
committerIbrahim Mkusa <ibrahimmkusa@gmail.com>2023-04-25 22:29:03 -0400
commitff58edc98a1224fa24a006b7d5273fbf0c1e2c29 (patch)
tree834647ae142f3a29a828527f16bde38ff4d411c2 /part1/unicafe/src/App.js
parent269ab61b887718ac5820b7f50cd9de3682944a5d (diff)
ex1.6
Diffstat (limited to 'part1/unicafe/src/App.js')
-rw-r--r--part1/unicafe/src/App.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/part1/unicafe/src/App.js b/part1/unicafe/src/App.js
new file mode 100644
index 0000000..efb32a2
--- /dev/null
+++ b/part1/unicafe/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