如何将 combineReducers 与 handleActions 一起使用
How to use combineReducers with handleActions
我正在尝试创建新的减速器 survey
,它必须结合 name
和 questions
减速器,同时使用 redux-actions
包中的 handleActions
。但是我收到一个错误 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
);
handleAction
实际上创建了一个reducer。直接使用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);
试试这个,告诉我它是否有效
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)
我正在尝试创建新的减速器 survey
,它必须结合 name
和 questions
减速器,同时使用 redux-actions
包中的 handleActions
。但是我收到一个错误 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
);
handleAction
实际上创建了一个reducer。直接使用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);
试试这个,告诉我它是否有效
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)