node.js - react+redux的计数器demo,reduers里的counter.jsx没有counter属性,为什么能点出来呢?
PHPz
PHPz 2017-04-17 14:43:20
0
2
581

这个那个官方的demo

reducers里的counter.jsx如图,这里的state里明明没有counter,但是actions里的counter.jsx却可以通过getState()来结构得到counter这个属性,我把{counter}换成{任意字幕}都不行

另外conatiners里的App.jsx也用到了,state能点出来counter这个

有没有大神能详细解释下马,为什么state会有counter这个属性,getState()是actions内置的方法吗,能得到reducer里的state?
谢谢

PHPz
PHPz

学习是最好的投资!

reply all(2)
巴扎黑

The data structure in redux is consistent with the combine structure of the reducer. The key of the data corresponds to the key of the reducer combine. If there is only one reducer, when creating the store, such as const store = createStore(counter); store.getState(); //得到的数据机构是{counter: xxx}. getState() is the api of redux. The user obtains the state of redux, which is all the data. The data obtained in the example is {counter: xxx}

左手右手慢动作
combineReducers({
  counter
})

will generate a state tree like this:

{
  counter: 0
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template