NickDelfino / nextjs-with-redux-and-cloud-firestore

Sample project using nextjs, redux, and cloud firestore.
82 stars 8 forks source link

Using combinedReducers creates invalid reducers #2

Open david-j-davis opened 6 years ago

david-j-davis commented 6 years ago

Hey Nick, I've tested your code with the implementation of index.js inside /reducers with:

import { combineReducers } from "redux";
import PostReducer from './PostReducer'

export default combineReducers({
  PostReducer
})

And inside store.js:

import { createStore, applyMiddleware } from 'redux'
import { composeWithDevTools } from 'redux-devtools-extension'
import thunkMiddleware from 'redux-thunk'
import reducer from './reducers/index';

export const initialState = {
  posts: [],
  userPost: ''
};

export const initStore = (initialState = initialState) => {
  return createStore(reducer, initialState, composeWithDevTools(applyMiddleware(thunkMiddleware)))
};

I'm getting the following error: No reducer provided for key "PostReducer" Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers. TypeError: Cannot read property 'map' of undefined

Thoughts about the problem?

NickDelfino commented 6 years ago

Hi David,

Thanks for the question!

This is a really interesting implementation question. At first glance, nothing is jumping out at me as wrong from the code provided. Were any changes made to the PostReducer?

If you want to upload your changes to GitHub I could run them locally and see if I can get to the bottom of it. Thanks!

Best, Nick

david-j-davis commented 6 years ago

No changes to PostReducer. I think it's because combineReducers is oppinionated. Im going to submit a pull request for your review.

NickDelfino commented 6 years ago

Sounds great! Thanks for looking into this!

david-j-davis commented 6 years ago

As you can tell, I didnt change much of the code but the combinereducer function breaks the build. Any thoughts?