0

before post i tried to read the super-answer of Dan Abramov in this post

I have a little problem in my code, i will be happy to understand my mistake:

1) this is my index file

import { combineReducers } from 'redux-immutable';

import { reducer as formReducer } from 'redux-form';
import appReducer from './appReducer';
import errorReducer from './errorReducer';
import loginReducer from './loginReducer';
import modalReducer from './modalReducer';
import changeRequestReducer from './changeRequestReducer';
import releaseReducer from './releaseReducer';
import releaseReviewReducer from './releaseReviewReducer';
import logoutReducer from './logoutReducer';
import customAvatarReducer from './customAvatarReducer';


    export default combineReducers({
      appReducer,
      errorReducer,
      loginReducer,
      changeRequestReducer,
      releaseReducer,
      modalReducer,
      releaseReviewReducer,
      form: formReducer,
      logoutReducer,
      customAvatarReducer,
    });

I tried to add this:

const rootReducer = (state, action) => {
  if (action.type === USER_LOGOUT) {
    const state = undefined;
  }

  return reducers(state, action);
};

const reducers = combineReducers({
  appReducer,
  errorReducer,
  loginReducer,
  changeRequestReducer,
  releaseReducer,
  modalReducer,
  releaseReviewReducer,
  form: formReducer,
  logoutReducer,
  customAvatarReducer,
});

and this is the tree of the files,

enter image description here

The problem is that i get the error " you reach the maximum call stack size "

What am I doing wrong ? I don't know if could be this the problem but we are using Immutable.js

UPDATE

This is the error received enter image description here

and this is the index file right now

import { combineReducers } from 'redux-immutable';
import { reducer as formReducer } from 'redux-form';
import appReducer from './appReducer';
import errorReducer from './errorReducer';
import loginReducer from './loginReducer';
import modalReducer from './modalReducer';
import changeRequestReducer from './changeRequestReducer';
import releaseReducer from './releaseReducer';
import releaseReviewReducer from './releaseReviewReducer';
import logoutReducer from './logoutReducer';
import customAvatarReducer from './customAvatarReducer';
import { USER_LOGOUT } from '../actions/logoutActions';

const rootReducer = (state, action) => {
  if (action.type === USER_LOGOUT) {
    const state = undefined;
  }

  return reducers(state, action);
};

const reducers = combineReducers({
  appReducer,
  errorReducer,
  loginReducer,
  changeRequestReducer,
  releaseReducer,
  modalReducer,
  releaseReviewReducer,
  form: formReducer,
  logoutReducer,
  customAvatarReducer,
  rootReducer,
});

export default reducers;
Legeo
  • 784
  • 4
  • 20
  • 44
  • 1
    this error is usually caused by you calling a function recursively with no exit condition – Davin Tryon Jun 27 '19 at 10:17
  • Thank you David for your comment and your time. Should I post more code to help you to understand what's going on? If yes, what section would be helpful ? – Legeo Jun 27 '19 at 10:20
  • 1
    does the error have a line number associated? If so, please post the code relevant to that line. – Davin Tryon Jun 27 '19 at 10:21
  • what are you trying to do inside the rootReducer function? As far as I know reducers should return state – Zoti Jun 27 '19 at 10:27
  • i just tried to followed the answer of Dan abramov in the link, but i don't really know how to implement it. – Legeo Jun 27 '19 at 10:30
  • have you tried to rename your `reducers` object to something else, `myReducers` for example? – Zoti Jun 27 '19 at 10:41
  • yup, but nothing. – Legeo Jun 27 '19 at 10:45

2 Answers2

2

Try to change

export default reducers;

to

export default rootReducer;
Arnas
  • 635
  • 8
  • 18
0

you only have to replace bit lines , try with below code.

const rootReducer = (state, action) => {
  if (action.type === USER_LOGOUT) {
    state = [];
  }

  return reducers(...state, action);
};
Vijay sadhu
  • 500
  • 4
  • 11
  • No, the state is still full, but at least i don't have the error of the max stack, plus the state is not iterable, i can post the error screen XD i going mad, really. – Legeo Jun 27 '19 at 11:00
  • try it with `state=undefined` or `state=Immutable.Map()` since https://github.com/gajus/redux-immutable#usage – Zoti Jun 27 '19 at 11:04
  • if you return reducer like this , then you get empty state(store) { return reducers(state, action); } – Vijay sadhu Jun 27 '19 at 11:46
  • @vijay sadhu, that's what Legeo wants, to reset/clear the state. – Zoti Jun 27 '19 at 12:25