@formvk/react 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # @formvk/react
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 65c066c: 添加readme.md文档
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [65c066c]
12
+ - @formvk/core@1.0.0
13
+ - @formvk/reactive@1.0.0
14
+ - @formvk/reactive-react@1.0.0
15
+ - @formvk/schema@1.0.0
16
+ - @formvk/shared@1.0.0
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # @formvk/react
2
+
3
+ React bindings for Formvk. It connects the `@formvk/core` form model and `@formvk/schema` to React components, with field updates powered by `@formvk/reactive-react`.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @formvk/react react react-dom
9
+ ```
10
+
11
+ `react` and `react-dom` (`>= 18`) are peer dependencies.
12
+
13
+ ## Usage
14
+
15
+ ```tsx
16
+ import { createForm, createSchema, createSchemaField, FormProvider } from '@formvk/react'
17
+ import { useState } from 'react'
18
+
19
+ function Input(props: { value?: string }) {
20
+ return <input value={props.value ?? ''} readOnly />
21
+ }
22
+
23
+ // schema and component factory are static: build them once at module scope
24
+ const { SchemaField, fragment: f } = createSchemaField({
25
+ components: { Input },
26
+ })
27
+
28
+ const schema = createSchema({
29
+ name: f.Input({ title: 'Name' }),
30
+ })
31
+
32
+ export default function App() {
33
+ // the form is a stateful model: create it lazily inside the component
34
+ const [form] = useState(() => createForm({ values: { name: '' } }))
35
+
36
+ return (
37
+ <FormProvider form={form}>
38
+ <SchemaField schema={schema} />
39
+ </FormProvider>
40
+ )
41
+ }
42
+ ```
43
+
44
+ ## API
45
+
46
+ - **Components** — `FormProvider`, `SchemaField`, `createSchemaField`, `RecursionField`, `ExpressionScope`, `FormConsumer`, `ReactiveField`.
47
+ - **Hooks** — `useForm`, `useField`, `useFieldSchema`, `useAttach`, `useFormEffects`, `useParentForm`.
48
+ - **Helpers** — `createForm`, `connect`, `mapProps`, `mapReadPretty`.
49
+ - **Schema** — re-exports `@formvk/schema` (`createFragment`, `createSchema`, `ISchema`, expression types, ...).
50
+
51
+ Components that read observable state directly should be wrapped with `observer` from `@formvk/reactive-react`. `FormConsumer` exposes form state through a render prop.
52
+
53
+ ## Documentation
54
+
55
+ - React API: https://formvk.github.io/core/api/react
56
+ - Getting started: https://formvk.github.io/core/guide/getting-started
57
+
58
+ ## License
59
+
60
+ MIT