Search code examples
react-nativeredux-promise-middleware

Unable to handle error: `middleware is not a function' in redux-promise-middleware?


I am trying to use redux-promise-middleware in my app, but when I am trying to run my app error comes with an error message: 'middleware is not a function or middleware is null'.

I tried to use middleware without a function as suggested in redux async docs, but still error is coming.

configureStore.js


import { createStore, applyMiddleware } from 'redux'
import app from './reducers/index';
import PromiseMiddleware from 'redux-promise-middleware';

const configureStore = () => {
    let middleware = applyMiddleware(PromiseMiddleware());
    let store = createStore(app, middleware);
    return store
};

export default configureStore;

index.js


import React from 'react'
import { AppRegistry } from 'react-native';
import App from './App';
import { Provider } from 'react-redux'
import configureStore from './configureStore'

const store = configureStore();

const ReduxMiddleware = () => {
    <Provider store={store}>
        <App />
    </Provider>
}

AppRegistry.registerComponent('ReduxMiddleware', () => ReduxMiddleware);

Please anybody, suggest to me that why I am facing this error. I am new to redux.


Solution

  • import promiseMiddleware from 'redux-promise-middleware';
    
    composeStoreWithMiddleware = applyMiddleware(
       promiseMiddleware,
    )(createStore);
    

    And not : PromiseMiddleware()

    (not uppercase and w/o () )