@36node/redux-form 中文文档教程

发布于 4年前 浏览 24 项目主页 更新于 3年前

Redux form

versiondownloads

Use

Config redux

import { formReducer } from "@36node/redux-form";

export default combineReducers({
  forms: formReducer,
});

Actions

import { createFormActions } from "@36node/redux-form";

const formActions = createFormActions("someKey");

dispatch(formActions.reset());

// Actions:

interface FormActions {
  // reset form with initialValues(Optional)
  reset: (initialValues: Object, meta?: Object) => ResetAction;
  // register field, note: once one name of field had registerred, repeat register action will be no effect
  registerField: (name: String, meta?: Object) => RegisterFieldAction;
  // register mutil fields, note: once one name of field had registerred, repeat register action will be no effect
  registerMutilFields: (
    fields: [{ name: String, initialValue: any }],
    meta?: Object
  ) => RegisterMutilFieldsAction;
  // change field state by name
  changeField: (
    name: String,
    fieldState: {
      name: String, //field name
      dirty?: Boolean, // is dirty
      touched?: Boolean, // is touched
      value?: any, // field value
      validating?: Boolean, // is validating
      errors?: any, // validate errors
    },
    meta?: Object
  ) => SetAction;
  // change mutil field state
  changeMutilFields: (
    fields: [
      {
        name: String, //field name
        dirty?: Boolean, // is dirty
        touched?: Boolean, // is touched
        value?: any, // field value
        validating?: Boolean, // is validating
        errors?: any, // validate errors
      },
    ],
    meta?: Object
  ) => ChangeMutilFieldsAction;
}

selector

import { createFormSelector } from "@36node/redux-form";

const formSelector = createFormSelector("someKey"),

const state = formSelector(state);

// Form State:

interface FormState {
  fields: {
    [name: String]: {
      name: String; //field name
      dirty?: Boolean; // is dirty
      touched?: Boolean; // is touched
      value?: any; // field value
      validating?: Boolean; // is validating
      errors?: any; // validate errors
    };
  };
  meta?: Object;
}

Redux form

versiondownloads

Use

Config redux

import { formReducer } from "@36node/redux-form";

export default combineReducers({
  forms: formReducer,
});

Actions

import { createFormActions } from "@36node/redux-form";

const formActions = createFormActions("someKey");

dispatch(formActions.reset());

// Actions:

interface FormActions {
  // reset form with initialValues(Optional)
  reset: (initialValues: Object, meta?: Object) => ResetAction;
  // register field, note: once one name of field had registerred, repeat register action will be no effect
  registerField: (name: String, meta?: Object) => RegisterFieldAction;
  // register mutil fields, note: once one name of field had registerred, repeat register action will be no effect
  registerMutilFields: (
    fields: [{ name: String, initialValue: any }],
    meta?: Object
  ) => RegisterMutilFieldsAction;
  // change field state by name
  changeField: (
    name: String,
    fieldState: {
      name: String, //field name
      dirty?: Boolean, // is dirty
      touched?: Boolean, // is touched
      value?: any, // field value
      validating?: Boolean, // is validating
      errors?: any, // validate errors
    },
    meta?: Object
  ) => SetAction;
  // change mutil field state
  changeMutilFields: (
    fields: [
      {
        name: String, //field name
        dirty?: Boolean, // is dirty
        touched?: Boolean, // is touched
        value?: any, // field value
        validating?: Boolean, // is validating
        errors?: any, // validate errors
      },
    ],
    meta?: Object
  ) => ChangeMutilFieldsAction;
}

selector

import { createFormSelector } from "@36node/redux-form";

const formSelector = createFormSelector("someKey"),

const state = formSelector(state);

// Form State:

interface FormState {
  fields: {
    [name: String]: {
      name: String; //field name
      dirty?: Boolean; // is dirty
      touched?: Boolean; // is touched
      value?: any; // field value
      validating?: Boolean; // is validating
      errors?: any; // validate errors
    };
  };
  meta?: Object;
}
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文