redux-form / immutable,如何在reducer.plugin中更新状态?

时间:2017-04-06 10:11:25

标签: redux immutability redux-form

目前我正在尝试在ma全新项目中使用redux-form / immutable,我遇到了一些我无法解决的问题(尤其是这个很酷的reducer.plugin),可能是我有点儿不可改变的新东西和类似的东西。

对主题表示赞赏,建议或帮助。

所以,首先:

import { combineReducers } from 'redux-immutable';

import routing from './routeReducer';
import { reducer as formReducer } from 'redux-form/immutable';
const rootReducer = combineReducers({
routing,
    form: formReducer.plugin({
        signupForm: (state, action) => {
            switch(action.type) {
                case 'SIGNUP_FACEBOOK':
                    return {
                        console.log(state);
                    }
                default:
                    return state
            }
        }
    })
});

虽然没有表单字段并触及此console.log(state)返回undefined,所以这里有一个问题:如何用某种状态初始化表单并实际更新某种操作('SIGNUP_FACEBOOK '对于这个例子)?

这是表单代码示例:

import React, { PropTypes } from 'react';
import { Field, reduxForm } from 'redux-form/immutable';
import renderInputControl from '../../../common/InputControl';
import validate from './validate';

const SignUpForm = (props) => {
    const { handleSubmit, submitting, invalid } = props;
    return (
        <form onSubmit={handleSubmit} className='signup__form'>
            <Field name='name' type='text' component={renderInputControl} label='Full Name'/>
            <Field name='email' type='email' component={renderInputControl} label='Email'/>
            <Field name='password' type='password' component={renderInputControl} label='Password'/>
            <Field name='tel' type='tel' component={renderInputControl} label='Phone Number'/>
            <button type='submit' disabled={submitting || invalid}>Sign Up</button>
         </form>
    );
};

SignUpForm.propTypes = {
    handleSubmit: PropTypes.func.isRequired,
    onSubmit: PropTypes.func,
    submitting: PropTypes.bool,
    invalid: PropTypes.bool
};

export default reduxForm({
    form: 'signupForm',
    validate
})(SignUpForm);

第二个问题是:即使我触摸了任何字段(因此它实际上得到了一些状态,例如console.log(state)返回Map ...),我应该如何更新它,couse code:

state.getIn(['fields', 'name']).set('visited', false).set('touched', false)

哪个应该设置'被触摸'和'被访问'为假没有做任何事情?

祝你好运!

0 个答案:

没有答案