|
@@ -1,7 +1,61 @@
|
|
-export default function counter() {
|
|
|
|
|
|
+import styles from './counter.module.css';
|
|
|
|
+import { addOne, reduceOne, addBy, asyncAddBy } from '../store/slices/counter';
|
|
|
|
+import { useSelector, useDispatch } from 'react-redux';
|
|
|
|
+import { useState } from 'react';
|
|
|
|
+
|
|
|
|
+// console.log(styles);
|
|
|
|
+
|
|
|
|
+function Counter() {
|
|
|
|
+ const c = useSelector(({ counter }) => counter.c);
|
|
|
|
+ const dispatch = useDispatch();
|
|
|
|
+ let [nc, setNC] = useState('');
|
|
|
|
+
|
|
return (
|
|
return (
|
|
<div>
|
|
<div>
|
|
<h3>计数器</h3>
|
|
<h3>计数器</h3>
|
|
|
|
+ <div className={styles.row}>
|
|
|
|
+ <button
|
|
|
|
+ className={styles.button}
|
|
|
|
+ onClick={() => {
|
|
|
|
+ dispatch(reduceOne());
|
|
|
|
+ }}
|
|
|
|
+ >
|
|
|
|
+ -
|
|
|
|
+ </button>
|
|
|
|
+ <span className={styles.value}>{c}</span>
|
|
|
|
+ <button
|
|
|
|
+ className={styles.button}
|
|
|
|
+ onClick={() => {
|
|
|
|
+ dispatch(addOne());
|
|
|
|
+ }}
|
|
|
|
+ >
|
|
|
|
+ +
|
|
|
|
+ </button>
|
|
|
|
+ </div>
|
|
|
|
+ <div className={styles.row}>
|
|
|
|
+ <input
|
|
|
|
+ className={styles.textbox}
|
|
|
|
+ value={nc}
|
|
|
|
+ onChange={(e) => setNC(e.target.value)}
|
|
|
|
+ />
|
|
|
|
+ <button
|
|
|
|
+ className={styles.button}
|
|
|
|
+ onClick={() => {
|
|
|
|
+ dispatch(addBy(Number(nc) || 0));
|
|
|
|
+ }}
|
|
|
|
+ >
|
|
|
|
+ Add Amount
|
|
|
|
+ </button>
|
|
|
|
+ <button
|
|
|
|
+ className={styles.asyncButton}
|
|
|
|
+ onClick={() => {
|
|
|
|
+ dispatch(asyncAddBy(Number(nc) || 0));
|
|
|
|
+ }}
|
|
|
|
+ >
|
|
|
|
+ Add Async
|
|
|
|
+ </button>
|
|
|
|
+ </div>
|
|
</div>
|
|
</div>
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
+export default Counter;
|