3

I'm trying to create new reducer survey, which must combine name and questions reducers while using handleActions from redux-actions package. But I recieve an error Invariant Violation: Expected handlers to be a plain object. How should I change it to actually work?

import { Map, List } from 'immutable';
import { combineReducers } from 'redux-immutable';
import { handleActions } from 'redux-actions';

const initialNameState = List();
const initialQuestionsState = List();

const name = handleActions({}, initialNameState);
const questions = handleActions({}, initialQuestionsState);

export const initialSurveyState = Map({
  name: initialNameState,
  questions: initialQuestionsState
});

export const survey = handleActions(
  combineReducers({
    name,
    questions
  }),
  initialSurveyState
);

TyraelS
  • 33
  • 4

2 Answers2

1

handleAction actually creates a reducer. Directly using combineReducer should solve the problem.

import React, { Component } from 'react';
import { render } from 'react-dom';
import { createStore, combineReducers } from 'redux';
import { connect, Provider } from 'react-redux';
import { Map, List } from 'immutable';
import { combineReducers } from 'redux-immutable';
import { handleActions, createAction, combineActions } from 'redux-actions';

const initialNameState = List();
const initialQuestionsState = List();

const name = handleActions({}, initialNameState);
const questions = handleActions({}, initialQuestionsState);

export const survey = combineReducers({name, questions});

const store = createStore(survey);
ajai Jothi
  • 2,284
  • 1
  • 8
  • 16
  • Thanks, it worked. But I'm still wondering if it can work without existing actions. I have many reducers which will handle different actions in the next stages of the development. Should I create dumb actions for them? – TyraelS Aug 23 '19 at 17:19
0

try this and tell me if it work or not

import { createStore, combineReducers } from 'redux';

const initialNameState = List();
const initialQuestionsState = List();

const name = handleActions({}, initialNameState);
const questions = handleActions({}, initialQuestionsState);

 const initialSurveyState = Map({
  name: initialNameState,
  questions: initialQuestionsState
});
    export const rootReducer=combineReducers({
    name,
    questions
  })

  const store=createStore(rootReducer)
Mohammed Al-Reai
  • 2,344
  • 14
  • 18