|
@@ -1,5 +1,7 @@
|
|
|
-import './Counter.css'
|
|
|
-import {addOne,reduceOne,addFree} from '../store/slice/counter'
|
|
|
+// import './Counter.css'
|
|
|
+import Style from './counter.module.css'
|
|
|
+import {addTwo,getAsyncAdd} from './counterslice'
|
|
|
+// import {addOne,reduceOne,addFree} from '../../store/slice/counter'
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
|
import { useRef } from 'react';
|
|
|
function Counter() {
|
|
@@ -8,23 +10,26 @@ function Counter() {
|
|
|
return state.counter.value
|
|
|
})
|
|
|
let dispatch = useDispatch()
|
|
|
- let inputRef = useRef(null)
|
|
|
+ // let inputRef = useRef(null)
|
|
|
return(
|
|
|
- <div className='counter'>
|
|
|
+ <div className={Style.box}>
|
|
|
<p>计数器:{count}</p>
|
|
|
<p>
|
|
|
<button onClick={()=>{
|
|
|
- dispatch(addOne())
|
|
|
+ dispatch(addTwo())
|
|
|
}}>增加</button>
|
|
|
|
|
|
<button onClick={()=>{
|
|
|
+ dispatch(getAsyncAdd)
|
|
|
+ }}>异步添加</button>
|
|
|
+ {/* <button onClick={()=>{
|
|
|
dispatch(reduceOne())
|
|
|
- }}>减少</button>
|
|
|
+ }}>减少</button> */}
|
|
|
</p>
|
|
|
<p>
|
|
|
- <input type="text" ref={inputRef} /><button onClick={()=>{
|
|
|
+ {/* <input type="text" ref={inputRef} /><button onClick={()=>{
|
|
|
dispatch(addFree(inputRef.current.value-0))
|
|
|
- }}>添加</button>
|
|
|
+ }}>添加</button> */}
|
|
|
</p>
|
|
|
</div>
|
|
|
)
|