createForms(forms, [model], [options])
import { combineReducers } from 'redux';
import { createForms } from 'react-redux-form';
const initialUserState = {};
const initialGoatState = {};
const reducer = combineReducers({
foo: fooReducer,
bar: barReducer,
...createForms({
user: initialUserState,
goat: initialGoatState,
}),
});
// reducer state shape will be:
// {
// foo: fooReducer,
// bar: barReducer,
// user: modelReducer('user', initialUserState),
// goat: modelReducer('goat', initialGoatState),
// forms: formReducer(''),
// }
The createForms() helper function takes a forms object where:
- each key is a string model path
- each value is either:
- (Any) an initial state, or
- (Function) an existing reducer
and turns it into an object where:
- each key/value pair is a
modelReducer() - a
'forms'key on the same object is a singleformReducer()that handles all forms for all models. (configurable inoptions)
Arguments
forms(Object): An object whose keys correspond to relative string model paths and whose values correspond to:- (Any) an initial state for the model, or
- (Function) an existing reducer for the model.
[model = ''](String): The string representation of the parent model containing the child models in theformsobject. Defaults to an empty string.[options](Object): An options object to override the default options forcombineForms():key(String): The singleformReducerkey. Defaults to'forms'.plugins(Array) : An array of plugins to pass into theformReducer(). Defaults to no plugins.
Returns
(Object): An object that is the mapping of each reducer or initial state to a modelReducer() and a .forms prop that contains the formReducer.
Notes
- The
createForms()function is meant to be used withcombineReducers()fromredux. Use it when you want a flatter combined reducer structure.