redux - Access State inside of mapDispatchToProps method -


i have written container component using redux , implementation mapdispathtoprops looks this

const mapdispatchtoprops = (dispatch, ownprops) => {     return {         onchange: (newvalue) => {             dispatch(updateattributeselection('genre', newvalue));             dispatch(gettabledata(newvalue, ownprops.currentyear));         }     } } 

the problem in order gettabledata need state of other components. how can access state object in method?

you can use redux-thunk create separate action creator function has access getstate, rather defining function inside mapdispatchtoprops:

function dotableactions(newvalue, currentyear) {     return (dispatch, getstate) => {         dispatch(updateattributeselection('genre', newvalue));         let state = getstate();         // logic based on state, , then:         dispatch(gettabledata(newvalue, currentyear));     } }   let mapdispatchtoprops = (dispatch, ownprops) => {     return {         onchange : (newvalue) => {             dispatch(dotableactions(newvalue, ownprops.currentyear))         }     } } 

some varying ways go organizing those, ought work.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -