I am a complete beginner, I’m following a tutorial on redux thunk and keep getting this error:
redux.js:642 Uncaught TypeError: middleware is not a function
at redux.js:642:1
at Array.map (<anonymous>)
at redux.js:641:1
at HTMLDocument.main (bootstrap.js:21:22)
This is the line:
const createStoreWithMiddleware = applyMiddleware(thunk)(createStore);
And this is my code:
import React from "react";
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
import { createStore, applyMiddleware } from "redux";
import { BrowserRouter, Switch, Route } from "react-router-dom";
import reducers from "./reducers";
import thunk from 'redux-thunk';
const createStoreWithMiddleware = applyMiddleware(thunk)(createStore);
import "./style/main.scss";
import Home from "./components/home";
import Results from "./components/results";
function main() {
ReactDOM.render(
<Provider store={createStoreWithMiddleware(reducers)}>
<BrowserRouter>
<Switch>
<Route path='/' exact component={Home}/>
<Route path='/results' component={Results}/>
</Switch>
</BrowserRouter>
</Provider>,
document.querySelector(".app-wrapper")
);
}
document.addEventListener("DOMContentLoaded", main);
The only thing I can add is that it works for my tutot but the tutorial is fairly old. In my code the “createStore” and “ReactDOM.render(” are crossed out.
We have been explained practically nothing (don’t tell me to leave the course ’cause I can’t), been reading what each thing is on my own and still don’t undestand much. It’s my first approach.
I have read other questions and have changede the import to:
import {thunk} from 'redux-thunk';
I’ve also tried:
const store = createStore(
reducers,
applyMiddleware(thunk)
);
npm install redux redux-thunk react-redux
I also didn’t know if I need to change anything else appart from that.
MrsSour is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.