这个那个官方的demo
reducers里的counter.jsx如图,这里的state里明明没有counter,但是actions里的counter.jsx却可以通过getState()来结构得到counter这个属性,我把{counter}换成{任意字幕}都不行
另外conatiners里的App.jsx也用到了,state能点出来counter这个
有没有大神能详细解释下马,为什么state会有counter这个属性,getState()是actions内置的方法吗,能得到reducer里的state?
谢谢
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}
will generate a state tree like this: