# 11.Redux学后感言
1.action工厂函数中, 同步方法返回一个对象, 异步方法返回一个函数
2.如果增加一个异步获取数据的代码, 需要改动的文件有 actions, action-types, reducers, app.js
3.如果有多个 reducer 函数, 需要进行合并, 还要更改 store, app文件
import {combineReducers} from 'redux'
const counter = (state = initComments, action) => ()
const comments = (state = initComments, action) => ()
export default combineReducers({
counter, // 指定reducer对应的属性
comments
})
// redux 向外暴露的state是个什么结构? 对象
// { counter: 2, comments: [] }
// 然后在 store 这样引入 ⭐⭐ 因为是 default暴露
import reducers from './reducers'
// container/app.js 容器组件 中 connet 方法也要发生改变(很重要) ⭐⭐
export default connect(
state => ({ comments: state.comments, counter: state.counter }), // state有多个reducer 此时是一个对象 ⭐⭐
{ addComment, deleteComment, getComments }
)(Home)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20