I am trying to use the createAction function but am met with the following error:
Uncaught Error: Actions may not have an undefined "type" property. Have you misspelled a constant?
I'm not sure why I am getting this but I am assuming it has to do with middleware but I've tried adding that too and it still wont work.
this is what my store looks like:
import { combineReducers, applyMiddleware, compose } from "redux";
import { configureStore } from "@reduxjs/toolkit";
import { routerMiddleware } from "react-router-redux";
import thunk from "redux-thunk";
import { apiMiddleware } from "redux-api-middleware";
import Immutable from "immutable";
import moduleReducers from "./reducers";
import routerReducer from "./reactRouterReducer";
export default function createStore(history, initialState) {
const middlewares = [thunk, apiMiddleware, routerMiddleware(history)];
const enhancers = compose(applyMiddleware(...middlewares));
const reducer = combineReducers({
router: routerReducer,
...moduleReducers,
});
const preLoadedState = Immutable.fromJS(initialState || {});
return configureStore({
reducer,
preLoadedState,
enhancers,
});
}
this is what my reducer looks like:
import { createAction } from "redux-api-middleware";
import { createSelector } from "reselect";
import deep from "deep-get-set";
import config from "../config/config";
const SET_PROJECT = "SET_PROJECT";
const SET_PROJECTS = "SET_PROJECTS";
const SET_LOADING = "SET_LOADING";
const SET_ERROR = "SET_ERROR";
const initialState = {
isLoading: false,
hasError: false,
user_projects: null,
project: null,
};
export const fetchProjectsList = () =>
createAction({
endpoint: `${config?.apiHost}/projects`,
method: "GET",
headers: [],
credentials: "include",
types: [SET_LOADING, SET_PROJECTS, SET_ERROR],
});
export default function reducer(state = initialState, action) {
switch (action.type) {
case SET_PROJECT: {
const newState = {
...state,
isLoading: false,
hasError: false,
project: action?.project,
};
return newState;
}
case SET_PROJECTS: {
const newState = {
...state,
isLoading: false,
hasError: false,
user_projects: action?.payload,
};
return newState;
}
case SET_LOADING: {
const newState = {
...state,
isLoading: true,
hasError: false,
project: action?.project,
};
return newState;
}
case SET_ERROR: {
const newState = {
...state,
isLoading: false,
hasError: true,
project: action?.project,
};
return newState;
}
default:
return state;
}
}
I've tried setting up my store in all sorts of ways with different redux versions and still get the same error. It's funny cause I used this exact same function for a class and was able to use it successfully but for some reason I am lost on why this isn't working now. I know for a fact that the createAction function takes an object with a types key. I'm out of options. PLEASE HELP!