reactjs - Bind action parameters in mapDispatchToProps -


i have submit button dispatch action. action's payload post data sent api. use bindactioncreators in mapdispatchtoprops:

const mapdispatchtoprops = (dispatch) => ({     actions:  bindactioncreators(formactions, dispatch) }); 

then in component bind onclick submit action:

<input type="submit" onclick={() => this.props.actions.submit(this.props.postdata)} /> 

i don't have give component post data in mapstatetoprops. i'd prefer give component action has post data binded submit function it's usage this:

<input type="submit" onclick={this.props.submit} /> 

is possible? don't have access state in mapdispatchtoprops

there third argument called mergeprops in connect method of react-redux supposed used in cases 1 described. in case can like:

const mapstatetoprops = state => ({ postdata: ... });  const mapdispatchtoprops = (dispatch) => ({   actions:  bindactioncreators(formactions, dispatch) });  const mergeprops = (stateprops, dispatchprops) => ({   submit: () => dispatchprops.actions.submit(stateprops.postdata), });  const connectedcomponent = connect(mapstatetoprops, mapdispatchtoprops, mergeprops)(component); 

note component not receive actions nor postdata, submit.


Comments

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -

c# - Populating Gridview inside Listview ItemTemplate On Web User Control from Code Behind -