formik和antd 的Form結合使用

官方文檔:https://formik.org/docs/api/withFormik

formik和antd 的Form結合使用

import { withFormik } from 'formik';
import {Form} from 'antd'

// 查詢表單初始化
    const SearchForm = withFormik({
      mapPropsToValues: (props: any) => {
        const { schema, data } = props;
        const _formData: any = {};
        if (schema) {
          // 設置初始值
          for (const key of Object.keys(schema)) {
            if (data[key]) {
              _formData[key] = data[key];
            }
          }
        }
        return _formData;
      },
      handleSubmit: this.handleSubmit,
    })(Form);



const schema = {
      name: {
        name: 'name',
        label: '名稱',
        component: 'input',
      },
 };


 // 初始化值
    const data = {
      name: 'test'
     
    };


<div className="query-content query-single">
            <SearchForm schema={schema} confirm="查詢" data={data} resetFormCustome={this.resetFormCustom} />
          </div>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章