aboutsummaryrefslogtreecommitdiff
path: root/part1/anecdotes/src/App.js
diff options
context:
space:
mode:
authorIbrahim Mkusa <ibrahimmkusa@gmail.com>2023-04-26 20:15:41 -0400
committerIbrahim Mkusa <ibrahimmkusa@gmail.com>2023-04-26 20:15:41 -0400
commit911544693232e3c5fb9da66a38419294fee12fb1 (patch)
treea6fc2f88a1b1d90195a9a55fa39f761126035d1b /part1/anecdotes/src/App.js
parentb87aa3654e9ab5fbb88f8dd108d67531d3a43bef (diff)
begin work on ex1.12
Diffstat (limited to 'part1/anecdotes/src/App.js')
-rw-r--r--part1/anecdotes/src/App.js37
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