redux-undo: Get Cannot read property 'length' of undefined

i try to implement redux-undo to my app so my reducers is like

const combine = combineReducers({ designer, activities:undoable(activities), activitySelectedIndex, activitySelectedId, activityTypes, componentSelectedIndex, router: routerReducer })

and also :

function mapDispachToProps(dispatch){ return bindActionCreators(Object.assign({},actionCreators,UndoActionCreators), dispatch); }

but i get this error : Uncaught TypeError: Cannot read property 'length' of undefined at lengthWithoutFuture (reducer.js:25) at insert (reducer.js:33) at reducer.js:307 at combination (combineReducers.js:132) at dispatch (createStore.js:179) at createStore (createStore.js:253) at applyMiddleware.js:38 at createStore (createStore.js:65) at Object.<anonymous> (Routes.js:27) at __webpack_require__ (bootstrap df649ed…:555)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 20 (3 by maintainers)

Most upvoted comments

For anyone in the future who face with this problem with SSR and hydration, here is a little workaround, which mimics undoable for the server bundle:

import clientUndoable from 'redux-undo';

const serverUndoable = reducer => (state = defaultState, action = {}, ...slices) => ({
  past: [],
  present: reducer(state.present || state, action, ...slices),
  future: [],
});

const undoable = reducer => (
  IS_SERVER_RENDERING ? serverUndoable(reducer) : clientUndoable(reducer)
);

@joelzimmer released beta9-9-7 with the newHistory function, let me know if that solves your issue

@hamdiwanis just so i’m clear - that’d be the default response in the reducer being wrapped? Just want to make sure I have full context on what you are saying.