I'm currently receiving the error TypeError: getState is not a function I'm attempting something similar to the example at 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 some of the code for readability.
I've also tried this and receive TypeError: dispatch is not a function
export function fetchCategoriesIfNeeded(){
return(dispatch, getState) =>{
var state = getState()
if(shouldFetchCategories(state)){
dispatch(fetchCategories())
}
}
}