I have two queries regarding react-redux connect
the connect can be called with two arguments mapStateToProps, mapDispatchToProps
<Provider store={store}> </Provider>
mapDispatchToProps
is a function that gets dispatch
function as argument. You're expected to return an object, where you map
keys with a function to dispatch an action.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.