我在App.js中有以下内容.出于调试目的,我可以console.log使用当前状态store.getState().
const App = () => {
const store = createStore(reducers);
console.log(store.getState());
return (
<Provider store={store}>
<Router />
</Provider>
);
};
export default App;
Run Code Online (Sandbox Code Playgroud)
现在我如何store.getState()从这个应用程序中的容器中控制console.log .
更新:在注释中的"连接"建议之后,这是容器中代码的底部:
export default connect(mapStateToProps, {
Decrease,
Increase,
selectNumber
})(TableGenerator);
Run Code Online (Sandbox Code Playgroud)
我在哪里添加getState()?
mapStateToProps第一个参数实际上是Redux状态.它实际上是一个抽象的getState().
const mapStateToProps = function(state, ownProps) {
// state is equivalent to store.getState()
// you then get the slice of data you need from the redux store
// and pass it as props to your component
return {
someData: state.someData
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4096 次 |
| 最近记录: |