I'm trying to apply redux in my reactjs app. I can't proceed because of these errors:
I'm sure that I already installed all the dependencies that I need. Here is a relevant part of my package.json
"dependencies": { "react-redux": "^5.0.6", "redux": "^3.7.2", "redux-logger": "^3.0.6", "redux-promise": "^0.5.3", "redux-thunk": "^2.2.0", }
Here is a part of my index.js that implements redux
import { createStore, applyMiddleware } from 'redux'; import { Provider } from 'react-redux'; import thunkMiddleware from 'redux-thunk'; import createLogger from 'redux-logger'; import reducers from './reducers'; const logger = createLogger(); const store = createStore(reducers, applyMiddleware( thunkMiddleware, logger ) ) ReactDOM.render( <Provider store={store}> <App /> </Provider>, document.getElementById('root') );
middleware) Middleware is the suggested way to extend Redux with custom functionality. Middleware lets you wrap the store's dispatch method for fun and profit. The key feature of middleware is that it is composable.
The word "thunk" is a programming term that means "a piece of code that does some delayed work". Rather than execute some logic now, we can write a function body or code that can be used to perform the work later.
redux-promise "teaches" dispatch how to accept promises, by intercepting the promise and dispatching actions when the promise resolves or rejects. Normally, dispatch returns whatever action object was passed in. Because middleware wrap around dispatch , they can also change what value is being returned.
According to the docs you are mixing up the usage of redux-logger
You either need to import the specific createLogger
function
import { createLogger } from 'redux-logger' const logger = createLogger({ // ...options });
Or use the default import
import logger from 'redux-logger'
And then your code should be fine
const store = createStore( reducers, applyMiddleware(thunkMiddleware, logger) )
import logger from 'redux-logger'; import thunk from 'redux-thunk'; import reduxPromiseMiddleware from 'redux-promise-middleware'; import { applyMiddleware, createStore } from 'redux'; const middleware = applyMiddleware(reduxPromiseMiddleware, thunk, logger); const store = createStore(reducer, middleware);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With