简体中文 | English
通过创建一个可观察对象来观察表单的模型操作, 表单项的受控直接通过_. 赋值。
简单几行代码就可以完成表单受控, 无需关心受控逻辑, 无需关心受控过程, 只需要知道受控结果和如何应用你的受控状态。
使用 npm
npm install react-form-simple
使用 yarn
yarn add react-form-simple
使用render函数创建表单项
import { useForm } from 'react-form-simple';
const { render } = useForm(fields, [config]);
使用组件形式创建表单项
import { Form, FormItem } from 'react-form-simple';
import Button from '@components/Button';
import React from 'react';
import { useForm } from 'react-form-simple';
export default function App() {
const { render, model } = useForm({
name: '',
age: '',
});
const renderName = render('name')(<input className="input" />);
const renderAge = render('age')(<input className="input" />);
const renderSubmit = (
<Button onClick={() => console.log(model)}>submit</Button>
);
return (
<>
{renderName}
{renderAge}
{renderSubmit}
</>
);
}
import Button from '@components/Button';
import React from 'react';
import { useForm } from 'react-form-simple';
export default function App() {
const { render, model, useWatch } = useForm({ name: '' });
const renderName = render('name')(<input className="input" />);
useWatch(
({ model }) => [model.name],
(value) => {
/** code */
},
);
return (
<>
{renderName}
{renderAge}
</>
);
}


加入微信群

$ claude mcp add react-form-simple \
-- python -m otcore.mcp_server <graph>