MCPcopy Index your code
hub / github.com/easy-form/react-form-simple

github.com/easy-form/react-form-simple @v1.6.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.6.3 ↗ · + Follow
372 symbols 1,019 edges 150 files 13 documented · 3%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

React-form-simple logo

CI NPM version NPM downloads Static Badge Static Badge Static Badge NPM npm bundle size (version) npm bundle size (version)

简体中文 | English

📚 Documentation

✨ Features

  • 通过创建一个可观察对象来观察表单的模型操作, 表单项的受控直接通过_. 赋值。

  • 简单几行代码就可以完成表单受控, 无需关心受控逻辑, 无需关心受控过程, 只需要知道受控结果和如何应用你的受控状态。

  • 每个表单项之间的渲染自动完全隔离, 不需要自行组织组件隔离。这将能够更快的处理表单输入后的响应速度, 以及很大程度的避免在大型动态数据下造成的页面卡顿。
  • 具有数据观测功能, 可以在某些场景下对整个表单或者某个具体的表单项进行单一或者统一的观察监测, 可以在你需要用表单项最新的值进行渲染的地方进行值的订阅。
  • 灵活的使用方式, 灵活的页面布局组合, 开发者可以根据自己的喜好和场景使用某种方式以及内置布局。在大多数场景下, 无需开发者手动布局。
  • 简约的 API 设计, 在操作表单的过程中, 简单的只需要引入两个 API, 就可以完成大部分工作。
  • 高度可扩展的表单接口, 轻易定制化表单。
  • 与第三方 UI 轻易集成。
  • 完整的类型推断。

📦 Installing

使用 npm

npm install react-form-simple

使用 yarn

yarn add react-form-simple

🔨 Usage

使用render函数创建表单项

import { useForm } from 'react-form-simple';

const { render } = useForm(fields, [config]);

使用组件形式创建表单项

import { Form, FormItem } from 'react-form-simple';

💻 Demo

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}
    </>
  );
}

🎧 Watch

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}
    </>
  );
}

📄 Unit Test

unit-test

unit-test

🤝 Community

加入微信群

wechat-group

📝 License

MIT

Extension points exported contracts — how you extend this code

IObserver (Interface)
(no doc) [2 implementers]
src/driver/ObserverDriver/type.d.ts
Triggers (Interface)
(no doc)
src/types/form.ts
UseFormItemContentController (Interface)
(no doc)
src/use/useFormItemContentController.ts
CustomProps (Interface)
(no doc)
docs/demos/_controller_custom_defineProps.tsx
CreateOptions (Interface)
(no doc)
src/driver/RenderDriver/index.ts
ShareApis (Interface)
(no doc)
src/types/form.ts
ExtraApisType (Interface)
(no doc)
src/use/useFormExtraApi.ts
CustomProps (Interface)
(no doc)
docs/demos/_controller_custom_format.tsx

Core symbols most depended-on inside this repo

render
called by 87
docs/demos/custom/_basic.tsx
useForm
called by 64
docs/demos/custom/_basic.tsx
render
called by 35
src/driver/RenderDriver/index.ts
useForm
called by 32
src/use/useForm.ts
validate
called by 28
src/use/useContextApi.ts
getUuid
called by 23
src/utils/util.ts
useSubscribe
called by 20
src/use/useSubscribe.ts
isMeaningful
called by 14
src/utils/util.ts

Shape

Function 272
Method 49
Interface 31
Class 20

Languages

TypeScript100%

Modules by API surface

src/driver/ValidDriver/ValidUtils.ts20 symbols
src/__tests__/react-form-simple.test.tsx19 symbols
src/driver/ObserverDriver/type.d.ts15 symbols
src/types/use.ts12 symbols
scripts/generateTypes.js12 symbols
src/driver/ObserverDriver/abstract/AbstractObserver.ts11 symbols
scripts/generateApimd.js11 symbols
src/use/useContextApi.ts10 symbols
src/use/useFormItemController.ts9 symbols
src/driver/ControllerDriver/controller.ts9 symbols
src/utils/util.ts8 symbols
src/driver/ObserverDriver/implementation/Watch.ts8 symbols

For agents

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

⬇ download graph artifact