diff --git a/redux/redux-reactRedux-toolkit-fix/src/containers/count/index.jsx b/redux/redux-reactRedux-toolkit-fix/src/containers/count/index.jsx index c6ebe75b6..490542d30 100644 --- a/redux/redux-reactRedux-toolkit-fix/src/containers/count/index.jsx +++ b/redux/redux-reactRedux-toolkit-fix/src/containers/count/index.jsx @@ -38,6 +38,27 @@ class Count extends Component{ ) } } +// 写法1 +// const mapStateToProps=state=>({state}) +// const mapDispatchToProps=dispatch=>({ +// jia:data=>dispatch(createIncreementAction(data)), +// jian:data=>dispatch(createDecreementAction(data)), +// jiaAsync:(data,time)=>dispatch(createIncreementAsyncAction(data,time)), +// }) +// const CountContainer=connect(mapStateToProps,mapDispatchToProps)(countUI) + +// 写法2 +// const CountContainer=connect( +// state=>({state}), +// dispatch=>({ +// jia:data=>dispatch(createIncreementAction(data)), +// jian:data=>dispatch(createDecreementAction(data)), +// jiaAsync:(data,time)=>dispatch(createIncreementAsyncAction(data,time)), +// }) +// ) +// (countUI) + +// 写法3 const CountContainer=connect( state=>({state}), { diff --git a/redux/redux-reactRedux-toolkit-pure/src/App.js b/redux/redux-reactRedux-toolkit-pure/src/App.js index bad6179f2..12029acef 100644 --- a/redux/redux-reactRedux-toolkit-pure/src/App.js +++ b/redux/redux-reactRedux-toolkit-pure/src/App.js @@ -1,7 +1,7 @@ import React, { useEffect } from 'react' // 导入React Redux提供的Hooks import { useDispatch, useSelector } from 'react-redux' -import reducer,{increment,decrement, fetchUsers, incrementByAmount} from './store/modules/users' +import {increment,decrement, fetchUsers, incrementByAmount} from './store/modules/users' export default function App(){ // 结构出 list @@ -9,14 +9,13 @@ export default function App(){ const dispatch = useDispatch() // 使用useEffect触发异步请求执行 - // useEffect(()=>{ - // dispatch(fetchUsers()) - // },[dispatch]) + useEffect(()=>{ + dispatch(fetchUsers()) + },[dispatch]) const reload=()=>{ dispatch(fetchUsers()) console.log(fetchUsers()) - } return (