1

I can't seem to figure this out. When I use the function applyMiddleware I am unable to pass any arguments in as I get the error invalid number of arguments, expected 0.

import {applyMiddleware, createStore} from "redux";
import logger from "redux-logger";
import rootReducer from "./root-reducer";

const middlewares = [logger];
const store = createStore(rootReducer, applyMiddleware(...middlewares));

export default store;
Chris
  • 51
  • 1
  • 8
  • `createStore` [has](https://redux.js.org/api/createstore) the following API: `createStore(reducer, [preloadedState], [enhancer])`. Try calling it like `createStore(rootReducer, undefined, applyMiddleware(...middlewares))` – Vitalii Jul 17 '21 at 15:08
  • That doesn't work either. I still get the same error. – Chris Jul 17 '21 at 15:10
  • What is the exact error message? – Vitalii Jul 17 '21 at 15:12
  • Invalid number of arguments, expected 0. – Chris Jul 17 '21 at 15:16
  • I don't know what could be wrong. Do you have a stack trace with that error? Maybe something in `./root-reducer` – Vitalii Jul 17 '21 at 15:25
  • Are you using an IntelliJ IDE by any chance? I got the same notice from my IDE when writing React code in PHPStorm. – Jan Dries Jan 28 '22 at 14:39

1 Answers1

0

Try using compose to compose your middleWare, should allow you to accept at least 1 argument

import { createStore, compose, applyMiddleware, combineReducers } from "redux";

const middlewares = [logger];
const composedEnhancers = compose(applyMiddleware(...middlewares))
const store = createStore(rootReducer, composedEnhancers);