0

First time working with redux with react.

Error in edge browser.

"Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers."

I searched on many posts like this. Redux store does not have a valid reducer

But I haven't find anything about this same exact issue:

store.js

    import { createStore, combineReducers, applyMiddleware } from 'redux';
    import thunk from 'redux-thunk'
    import { composeWithDevTools } from 'redux-devtools-extension'
    
    const reducer = combineReducers({})
  
    const initialState = {}
     
    const middleware = [thunk]
    
    const store = createStore(reducer, initialState,
          composeWithDevTools(applyMiddleware(...middleware)))
    
    export default store

index.js

    import React from 'react';
    import ReactDOM from 'react-dom';
    import { Provider } from 'react-redux'
    import store from './store'
    import './index.css';
    import './bootstrap.min.css'
    import App from './App';
    import reportWebVitals from './reportWebVitals';
    
    ReactDOM.render(
      <Provider store={store}>
        <App />
      </Provider>,
      document.getElementById('root')
    );
    
    // If you want to start measuring performance in your app, pass a function
    // to log results (for example: reportWebVitals(console.log))
    // or send to an analytics endpoint. Learn more.
    reportWebVitals();

EDIT (Solution as mentioned by a friend bellow):

store.js Edited informations added to file store.js

import { productListReducer } from './reducers/productReducers';

const reducer = combineReducers({
    productList: productListReducer,
})

productReducer.js

The professor added a file called /reducers/productReducer.js

export const productListReducer = (state = { products: [] }, action ) => {
    switch(action.type) {
        case 'PRODUCT_LIST_REQUEST':
            return {loading:true, products:[]};
        case 'PRODUCT_LIST_SUCCESS':            
            return {loading:false, products:action.payload};
        case 'PRODUCT_LIST_FAIL':
            return {loading:false, error:action.payload};
        default:
            return state
    }
}
jeremy
  • 37
  • 5

1 Answers1

1

The Problem is that you are not passing any reducer to be combined by "combineReducers". Sice You are not passing any reducer there's no one to listen to the actions.

Ex: import myReducer from './reducers' const reducer = combineReducer( { myReducer:myReducer })

then you can pass this to your store.

shiv k
  • 24
  • 4
  • I'm doing a course and current video the code is this same. I'm going to do next video to see how to fill it. I think you're right my friend. – jeremy May 07 '21 at 12:31
  • It works! You're totally correct. It is filled on next course video and the professor filled up this parameter with productList and it is working fine now! – jeremy May 07 '21 at 12:46