javascript - react-redux with thunk - getState is not a function -
i'm receiving error typeerror: getstate not function i'm attempting similar example @ http://redux.js.org/docs/advanced/asyncactions.html
action.js - error occurs here
export const fetchcategoriesifneeded = (dispatch, getstate) => { if(shouldfetchcategories(getstate())){ return dispatch(fetchcategories()) } }
app.js
componentdidmount(){ this.props.dispatch(fetchcategoriesifneeded()) }
...
const mapstatetoprops = (state, props) => { return { isfetching: state.isfetching, categories: state.categories } }
reducer.js
function data (state = initialstate, action){ switch(action.type){ case receive_categories: return { ...state, isfetching: false, categories: action.categories } case request_categories: return { ...state, isfetching: true } default: return state } return state }
omitted of code readability.
i've tried , receive typeerror: dispatch not function
export function fetchcategoriesifneeded(){ return(dispatch, getstate) =>{ var state = getstate() if(shouldfetchcategories(state)){ dispatch(fetchcategories()) } } }
wiki
Comments
Post a Comment