diff options
author | Adrián Oliva <adrian.oliva@cimat.mx> | 2023-05-16 19:52:29 -0600 |
---|---|---|
committer | Adrián Oliva <adrian.oliva@cimat.mx> | 2023-05-16 19:52:29 -0600 |
commit | 17c1d3d2070ee0c060c3e71a9e5868f004b2b034 (patch) | |
tree | c0e7cf17901196b089291c63e8f97058068aed35 /src/features/counter/Counter.jsx | |
download | ToDo-App-FE-17c1d3d2070ee0c060c3e71a9e5868f004b2b034.tar.gz ToDo-App-FE-17c1d3d2070ee0c060c3e71a9e5868f004b2b034.zip |
Start point.
Visit https://github.com/nvh95/vite-react-template-redux to see original
template.
Diffstat (limited to 'src/features/counter/Counter.jsx')
-rw-r--r-- | src/features/counter/Counter.jsx | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/features/counter/Counter.jsx b/src/features/counter/Counter.jsx new file mode 100644 index 0000000..37d866d --- /dev/null +++ b/src/features/counter/Counter.jsx @@ -0,0 +1,67 @@ +import React, { useState } from "react"; +import { useSelector, useDispatch } from "react-redux"; +import { + decrement, + increment, + incrementByAmount, + incrementAsync, + incrementIfOdd, + selectCount, +} from "./counterSlice"; +import styles from "./Counter.module.css"; + +export function Counter() { + const count = useSelector(selectCount); + const dispatch = useDispatch(); + const [incrementAmount, setIncrementAmount] = useState("2"); + + const incrementValue = Number(incrementAmount) || 0; + + return ( + <div> + <div className={styles.row}> + <button + className={styles.button} + aria-label="Decrement value" + onClick={() => dispatch(decrement())} + > + - + </button> + <span className={styles.value}>{count}</span> + <button + className={styles.button} + aria-label="Increment value" + onClick={() => dispatch(increment())} + > + + + </button> + </div> + <div className={styles.row}> + <input + className={styles.textbox} + aria-label="Set increment amount" + value={incrementAmount} + onChange={(e) => setIncrementAmount(e.target.value)} + /> + <button + className={styles.button} + onClick={() => dispatch(incrementByAmount(incrementValue))} + > + Add Amount + </button> + <button + className={styles.asyncButton} + onClick={() => dispatch(incrementAsync(incrementValue))} + > + Add Async + </button> + <button + className={styles.button} + onClick={() => dispatch(incrementIfOdd(incrementValue))} + > + Add If Odd + </button> + </div> + </div> + ); +} |