我正在尝试创建新的减速器survey
,在使用name
包中的questions
时,它必须结合handleActions
和redux-actions
减速器。但是我收到一个错误Invariant Violation: Expected handlers to be a plain object.
,该如何更改它才能正常工作?
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
);
答案 0 :(得分:1)
handleAction
实际上创建了一个减速器。直接使用combineReducer
应该可以解决问题。
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);
答案 1 :(得分:1)
尝试一下,告诉我是否可行
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)