1

I am trying to use enhanced object literal syntax in my redux reducer, and some of them are working while others return empty objects. Is there a reason why 'form', and 'auth' work fine in my example, but 'files' does not? When I change 'files' to the traditional syntax, it works just fine. When I execute the example below, it just returns an empty object

import { combineReducers } from 'redux';
import auth from './auth_reducer';
import userReducer from './user_reducer';
import propertyReducer from './property_reducer';
import files from './file_upload_reducer';
import { reducer as form } from 'redux-form';


const appReducer = combineReducers({
  /* your app’s top-level reducers */
  form,
  auth,
  user: userReducer,
  properties: propertyReducer,
  files
})

const rootReducer = (state, action) => {
  if (action.type === 'UNAUTH_USER') {
    state = undefined
  }

  return appReducer(state, action)
}

export default rootReducer; 
Michael Lee
  • 458
  • 1
  • 8
  • 18
  • 1
    You’re saying `files: files` works? That would be extremely strange. What do they each compile to? – Ry- Apr 12 '18 at 01:48
  • I'm actually mistaken, it only works sporadically when I do files: files. How should this work? For additional context, I'm trying to upload a file using react-dropzone, and hold that file in my redux state store – Michael Lee Apr 12 '18 at 01:53
  • @MichaelLee Whatever your file_upload_reducer is exporting is not a proper reducer apparently. Your syntax is fine otherwise. Btw an action that needs to reset multiple reducers is usually done differently. You'd dispatch multiple actions from the place where logout/unauth is triggered. Each action resets one dedicated reducer. Then your appReducer would be your rootReducer. Note how the comment in it talks about "top level reducers"? They're not top-level if they aren't in the root reducer. – timotgl Apr 12 '18 at 07:59
  • I think i found the issue, seems like a redux store is not the right place to put a file. See this: https://github.com/reactjs/redux/issues/2276 Regarding your other comment, I'm following this pattern to cleat a redux store on log out: https://stackoverflow.com/questions/35622588/how-to-reset-the-state-of-a-redux-store – Michael Lee Apr 12 '18 at 11:59

0 Answers0