. Advertisement .
..3..
. Advertisement .
..4..
I encountered the following problem in completing my work:
TypeError: Cannot read property 'apply' of undefined
Below is the code I ran:
import { createStore, applyMiddleware,compose } from 'redux';
import thunk from 'redux-thunk';
import rootReducer from './reducers';
const initialState={};
const middleware = [thunk];
const store = createStore(rootReducer,initialState,
compose(
applyMiddleware(...middleware),
window.__REDUX_DEVTOOLS_EXTENSION__&& window.__REDUX_DEVTOOLS_EXTENSION__()
)
);
export default store;
"@material-ui/core": "^3.3.1",
"@material-ui/icons": "^3.0.1",
"axios": "^0.18.0",
"jwt-decode": "^2.2.0",
"prop-types": "^15.6.2",
"react": "^16.6.0",
"react-dom": "^16.6.0",
"react-redux": "^5.1.0",
"react-router-dom": "^4.3.1",
"react-scripts": "2.0.5",
"react-select": "^2.1.1",
"recharts": "^1.3.5",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0",
"typeface-roboto": "0.0.54"
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.3",
"express": "^4.16.4",
"mongoose": "^5.3.11",
"multer": "^1.4.1",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"path": "^0.12.7",
"validator": "^10.9.0",
"xlsx": "^0.14.1"
},
"devDependencies": {
"concurrently": "^4.0.1",
"nodemon": "^1.18.6",
},
What’s causing it, and how can it be resolved in the “typeerror: cannot read property ‘apply’ of undefined“ in the javascript?
The cause: This error happens because
compose
fromredux
wants all of its parameters to be functions. As a result,returns a boolean when it is evaluated in that environment.
Solution: To solve this error, you’d have to return a function that doesn’t return anything.
This was the same problem I encountered when I tried to test my web application on an incognito browser (extensions do not show up in incognito windows).
compose
fromredux
assumes that all arguments should be functions. What then?It returns a boolean if it is evaluated in this environment.
@knutwalker pointed out. It would be necessary to return a function which returns nothing. It worked for me.