[英]React-Redux connect
I have two queries regarding react-redux connect我有两个关于 react-redux connect 的问题
the connect can be called with two arguments mapStateToProps, mapDispatchToProps可以使用两个参数 mapStateToProps、mapDispatchToProps 调用连接
<Provider store={store}> </Provider>
如果我错了,请纠正我, <Provider store={store}> </Provider>
mapDispatchToProps
is a function that gets dispatch
function as argument. mapDispatchToProps
是一个以dispatch
函数为参数的函数。 You're expected to return an object, where you map
keys with a function to dispatch an action.你应该返回一个对象,在那里你用一个函数map
键来调度一个动作。
Example time:示例时间:
connect(/* ...*/, function(dispatch) {
return {
sayHello: function() { dispatch("ACTION_TYPE_HELLO")}
}
}
Connected components will receive prop sayHello
, which is a function, where this.props.sayHello()
will dispatch an action ACTION_TYPE_HELLO
to the store.连接的组件将接收 prop sayHello
,这是一个函数, this.props.sayHello()
将向 store 发送一个动作ACTION_TYPE_HELLO
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.