@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.
@@ -1,598 +0,0 @@
1
- import type { SchemaKey } from '@formvk/schema'
2
- import { act, cleanup } from '@testing-library/react'
3
- import { afterEach, describe, expect, expectTypeOf, test } from 'vitest'
4
-
5
- import {
6
- FormProvider,
7
- RecursionField,
8
- Schema,
9
- SchemaField,
10
- createForm,
11
- createSchemaField,
12
- useField,
13
- useFieldSchema,
14
- } from '..'
15
- import { Input, mountWithForm } from './shared'
16
-
17
- afterEach(cleanup)
18
-
19
- function SlotContainer(props: any) {
20
- return (
21
- <div className="slot-container">
22
- <div className="header">{props.slots?.header}</div>
23
- <div className="default">{props.slots?.default}</div>
24
- </div>
25
- )
26
- }
27
- SlotContainer.displayName = 'SlotContainer'
28
-
29
- function ArrayList() {
30
- const field = useField() as any
31
- const schema = useFieldSchema() as any
32
- const items = schema?.items
33
- const list = Array.isArray(field?.value) ? field.value : []
34
- return (
35
- <div className="array-list">
36
- {list.map((_: any, index: number) => (
37
- <RecursionField key={index} schema={items} name={index} basePath={field.address} />
38
- ))}
39
- </div>
40
- )
41
- }
42
- ArrayList.displayName = 'ArrayList'
43
-
44
- describe('SchemaField / RecursionField', () => {
45
- test('JSON schema 基础渲染:object 下的 string / boolean / number 子字段', () => {
46
- const form = createForm({ values: { s: 'text', b: true, n: 3 } })
47
- const view = mountWithForm(
48
- form,
49
- <SchemaField
50
- components={{ Input }}
51
- schema={{
52
- type: 'object',
53
- properties: {
54
- s: { type: 'string', component: 'Input' },
55
- b: { type: 'boolean', component: 'Input' },
56
- n: { type: 'number', component: 'Input' },
57
- },
58
- }}
59
- />
60
- )
61
-
62
- const inputs = Array.from(view.container.querySelectorAll('input'))
63
- expect(inputs.map(input => input.value)).toEqual(['text', 'true', '3'])
64
- expect(inputs.map(input => input.getAttribute('data-testid'))).toEqual(['s', 'b', 'n'])
65
- expect((form.fields['b'] as any).displayName).toBe('Field')
66
- })
67
-
68
- test('properties 的 index 控制渲染顺序', () => {
69
- const form = createForm()
70
- const view = mountWithForm(
71
- form,
72
- <SchemaField
73
- components={{ Input }}
74
- schema={{
75
- type: 'object',
76
- properties: {
77
- a: { type: 'string', component: 'Input', index: 2 },
78
- b: { type: 'string', component: 'Input', index: 0 },
79
- c: { type: 'string', component: 'Input', index: 1 },
80
- },
81
- }}
82
- />
83
- )
84
-
85
- expect(
86
- Array.from(view.container.querySelectorAll('input')).map(input => input.getAttribute('data-testid'))
87
- ).toEqual(['b', 'c', 'a'])
88
- })
89
-
90
- test('onlyRenderSelf 只创建自身字段,onlyRenderProperties 只渲染子属性', () => {
91
- const selfForm = createForm()
92
- const selfView = mountWithForm(
93
- selfForm,
94
- <SchemaField
95
- name="obj"
96
- onlyRenderSelf
97
- components={{ Input }}
98
- schema={{
99
- type: 'object',
100
- properties: {
101
- a: { type: 'string', component: 'Input' },
102
- },
103
- }}
104
- />
105
- )
106
-
107
- expect(selfForm.fields['obj']).toBeTruthy()
108
- expect(selfForm.fields['obj.a']).toBeUndefined()
109
- expect(selfView.container.querySelector('input')).toBeNull()
110
-
111
- const propsForm = createForm()
112
- const propsView = mountWithForm(
113
- propsForm,
114
- <SchemaField
115
- name="obj"
116
- onlyRenderProperties
117
- components={{ Input }}
118
- schema={{
119
- type: 'object',
120
- properties: {
121
- a: { type: 'string', component: 'Input' },
122
- },
123
- }}
124
- />
125
- )
126
-
127
- expect(propsForm.fields['obj']).toBeUndefined()
128
- expect(propsForm.fields['obj.a']).toBeTruthy()
129
- expect(propsView.container.querySelector('input')).toBeTruthy()
130
- })
131
-
132
- test('mapProperties 替换子 schema,filterProperties 过滤子节点', () => {
133
- const form = createForm()
134
- const view = mountWithForm(
135
- form,
136
- <SchemaField
137
- components={{ Input }}
138
- mapProperties={(schema: any, name: SchemaKey) =>
139
- name === 'a' ? { type: 'string', component: 'Input', componentProps: { placeholder: 'mapped' } } : undefined
140
- }
141
- filterProperties={(_schema: any, name: SchemaKey) => name !== 'b'}
142
- schema={{
143
- type: 'object',
144
- properties: {
145
- a: { type: 'string', component: 'Input' },
146
- b: { type: 'string', component: 'Input' },
147
- c: { type: 'string', component: 'Input' },
148
- },
149
- }}
150
- />
151
- )
152
-
153
- expect(view.container.querySelectorAll('input')).toHaveLength(2)
154
- expect(view.container.querySelector('[data-testid="a"]')!.getAttribute('placeholder')).toBe('mapped')
155
- expect(view.container.querySelector('[data-testid="b"]')).toBeNull()
156
- expect(view.container.querySelector('[data-testid="c"]')).toBeTruthy()
157
- })
158
-
159
- test('void 字段通过 slot 把子节点渲染到具名插槽', () => {
160
- const form = createForm()
161
- const view = mountWithForm(
162
- form,
163
- <SchemaField
164
- components={{ Input, SlotContainer }}
165
- schema={{
166
- type: 'object',
167
- properties: {
168
- v: {
169
- type: 'void',
170
- component: 'SlotContainer',
171
- properties: {
172
- a: { type: 'string', component: 'Input', slot: 'header' },
173
- },
174
- },
175
- },
176
- }}
177
- />
178
- )
179
-
180
- expect(view.container.querySelector('.slot-container .header input')).toBeTruthy()
181
- expect(view.container.querySelector('.slot-container .default')!.textContent).toBe('')
182
- expect((form.fields['v'] as any).displayName).toBe('VoidField')
183
- })
184
-
185
- test('array 字段按 items 渲染子节点', () => {
186
- const form = createForm({ values: { arr: ['x', 'y'] } })
187
- const view = mountWithForm(
188
- form,
189
- <SchemaField
190
- components={{ Input, ArrayList }}
191
- schema={{
192
- type: 'object',
193
- properties: {
194
- arr: {
195
- type: 'array',
196
- component: 'ArrayList',
197
- items: { type: 'string', component: 'Input' },
198
- },
199
- },
200
- }}
201
- />
202
- )
203
-
204
- const inputs = Array.from(view.container.querySelectorAll('input'))
205
- expect(inputs[0].getAttribute('data-testid')).toBe('arr.0')
206
- expect(inputs[1].getAttribute('data-testid')).toBe('arr.1')
207
- expect(inputs.map(input => input.value)).toEqual(['x', 'y'])
208
- expect((form.fields['arr'] as any).displayName).toBe('ArrayField')
209
- })
210
-
211
- test('scope 表达式读取 $values 并在依赖值变化后重新编译', async () => {
212
- const form = createForm({ values: { source: 'abc' } })
213
- const view = mountWithForm(
214
- form,
215
- <SchemaField
216
- components={{ Input }}
217
- schema={{
218
- type: 'object',
219
- properties: {
220
- source: { type: 'string', component: 'Input' },
221
- target: {
222
- type: 'string',
223
- component: 'Input',
224
- componentProps: { placeholder: '{{$values.source}}' },
225
- },
226
- },
227
- }}
228
- />
229
- )
230
-
231
- expect(view.container.querySelector('[data-testid="target"]')!.getAttribute('placeholder')).toBe('abc')
232
-
233
- await act(async () => {
234
- form.setValuesIn('source', 'changed')
235
- })
236
-
237
- expect(view.container.querySelector('[data-testid="target"]')!.getAttribute('placeholder')).toBe('changed')
238
- })
239
-
240
- test('reactions 的 dependencies / when 驱动 visible 变化', async () => {
241
- const form = createForm({ values: { hide: false } })
242
- const view = mountWithForm(
243
- form,
244
- <SchemaField
245
- components={{ Input }}
246
- schema={{
247
- type: 'object',
248
- properties: {
249
- hide: { type: 'boolean', component: 'Input' },
250
- target: {
251
- type: 'string',
252
- component: 'Input',
253
- reactions: [
254
- {
255
- dependencies: ['hide'],
256
- when: '{{$values.hide === true}}',
257
- fulfill: { state: { visible: false } },
258
- otherwise: { state: { visible: true } },
259
- },
260
- ],
261
- },
262
- },
263
- }}
264
- />
265
- )
266
-
267
- expect(view.container.querySelector('[data-testid="target"]')).toBeTruthy()
268
-
269
- await act(async () => {
270
- form.setValuesIn('hide', true)
271
- })
272
- expect(view.container.querySelector('[data-testid="target"]')).toBeNull()
273
-
274
- await act(async () => {
275
- form.setValuesIn('hide', false)
276
- })
277
- expect(view.container.querySelector('[data-testid="target"]')).toBeTruthy()
278
- })
279
-
280
- test('SchemaField 接受扁平 components,同名组件可在 props 层覆盖', () => {
281
- function InputA(props: any) {
282
- return <input className="input-a" {...props} />
283
- }
284
- function InputB(props: any) {
285
- return <input className="input-b" {...props} />
286
- }
287
-
288
- const schema = {
289
- type: 'object',
290
- properties: {
291
- a: { type: 'string', component: 'Input' },
292
- },
293
- }
294
-
295
- const formA = createForm()
296
- const viewA = mountWithForm(formA, <SchemaField schema={schema} components={{ Input: InputA }} />)
297
- expect(viewA.container.querySelector('.input-a')).toBeTruthy()
298
- expect(viewA.container.querySelector('.input-b')).toBeNull()
299
-
300
- const formB = createForm()
301
- const viewB = mountWithForm(formB, <SchemaField components={{ Input: InputB }} schema={schema} />)
302
- expect(viewB.container.querySelector('.input-b')).toBeTruthy()
303
- expect(viewB.container.querySelector('.input-a')).toBeNull()
304
- })
305
-
306
- test('schema 引用变化后重建字段并渲染新节点', async () => {
307
- const form = createForm()
308
- let schema: any = {
309
- type: 'object',
310
- properties: {
311
- a: { type: 'string', component: 'Input' },
312
- },
313
- }
314
- const view = mountWithForm(form, <SchemaField components={{ Input }} schema={schema} />)
315
-
316
- const first = form.fields['a'] as any
317
- expect(first.mounted).toBe(true)
318
-
319
- schema = {
320
- type: 'object',
321
- properties: {
322
- b: { type: 'string', component: 'Input' },
323
- },
324
- }
325
- view.rerender(
326
- <FormProvider form={form}>
327
- <SchemaField components={{ Input }} schema={schema} />
328
- </FormProvider>
329
- )
330
-
331
- expect(first.unmounted).toBe(true)
332
- expect(form.fields['b']).toBeTruthy()
333
- expect(view.container.querySelector('input')!.getAttribute('data-testid')).toBe('b')
334
- })
335
-
336
- test('hotReload:schema 引用变化后按新 schema 重建字段并保留值', () => {
337
- const form = createForm({ values: { a: 'keep', b: 'stale' } })
338
- let schema: any = {
339
- type: 'object',
340
- properties: {
341
- a: { type: 'string', component: 'Input', title: 'old-title' },
342
- b: { type: 'string', component: 'Input' },
343
- },
344
- }
345
- const view = mountWithForm(form, <SchemaField hotReload components={{ Input }} schema={schema} />)
346
-
347
- const firstA = form.fields['a'] as any
348
- expect(firstA.title).toBe('old-title')
349
-
350
- schema = {
351
- type: 'object',
352
- properties: {
353
- a: { type: 'string', component: 'Input', title: 'new-title' },
354
- c: { type: 'string', component: 'Input' },
355
- },
356
- }
357
- view.rerender(
358
- <FormProvider form={form}>
359
- <SchemaField hotReload components={{ Input }} schema={schema} />
360
- </FormProvider>
361
- )
362
-
363
- expect(form.fields['a']).not.toBe(firstA)
364
- expect((form.fields['a'] as any).title).toBe('new-title')
365
- expect(form.values.a).toBe('keep')
366
- expect(form.values.b).toBeUndefined()
367
- expect(form.fields['b']).toBeUndefined()
368
- expect(form.fields['c']).toBeTruthy()
369
- expect(
370
- Array.from(view.container.querySelectorAll('input')).map(input => input.getAttribute('data-testid'))
371
- ).toEqual(['a', 'c'])
372
- })
373
-
374
- test('schema prop 支持直接传入 Schema 实例', () => {
375
- const form = createForm({ values: { a: 'instance' } })
376
- const schema = new Schema({
377
- type: 'object',
378
- properties: {
379
- a: { type: 'string', component: 'Input' },
380
- },
381
- })
382
- const view = mountWithForm(form, <SchemaField components={{ Input }} schema={schema} />)
383
-
384
- expect(view.container.querySelector('input')!.value).toBe('instance')
385
- })
386
-
387
- test('无 properties 的 object schema 渲染为空', () => {
388
- const form = createForm()
389
- const view = mountWithForm(form, <SchemaField components={{ Input }} schema={{ type: 'object' }} />)
390
-
391
- expect(view.container.querySelector('input')).toBeNull()
392
- expect(Object.keys(form.fields)).toHaveLength(0)
393
- })
394
-
395
- test('onlyRenderProperties 无 name 时渲染当前 schema 的子属性', () => {
396
- const form = createForm()
397
- const view = mountWithForm(
398
- form,
399
- <SchemaField
400
- onlyRenderProperties
401
- components={{ Input }}
402
- schema={{
403
- type: 'object',
404
- properties: {
405
- a: { type: 'string', component: 'Input' },
406
- },
407
- }}
408
- />
409
- )
410
-
411
- expect(view.container.querySelector('input')!.getAttribute('data-testid')).toBe('a')
412
- })
413
-
414
- test('void + onlyRenderProperties 只渲染子属性且不创建自身字段', () => {
415
- const form = createForm()
416
- const view = mountWithForm(
417
- form,
418
- <SchemaField
419
- name="v"
420
- onlyRenderProperties
421
- components={{ Input }}
422
- schema={{
423
- type: 'void',
424
- properties: {
425
- a: { type: 'string', component: 'Input' },
426
- },
427
- }}
428
- />
429
- )
430
-
431
- expect(form.fields['v']).toBeUndefined()
432
- expect(form.fields['v.a']).toBeTruthy()
433
- expect(view.container.querySelector('input')!.getAttribute('data-testid')).toBe('v.a')
434
- })
435
- })
436
-
437
- function TypedInput(props: { maxLength?: number; placeholder?: string }) {
438
- return <input {...props} />
439
- }
440
- TypedInput.displayName = 'TypedInput'
441
-
442
- function TypedArray(_props: { maxItems?: number }) {
443
- return <div />
444
- }
445
- TypedArray.displayName = 'TypedArray'
446
-
447
- function TypedLayout(_props: { colon?: boolean }) {
448
- return <div />
449
- }
450
- TypedLayout.displayName = 'TypedLayout'
451
-
452
- const demoComponents = {
453
- Input: TypedInput,
454
- }
455
-
456
- describe('createSchemaField 返回 SchemaField + fragment', () => {
457
- test('运行时:工厂返回 { SchemaField, fragment } 双 key', () => {
458
- const built = createSchemaField({ components: { Input: TypedInput } })
459
-
460
- expect(Object.keys(built).sort()).toEqual(['SchemaField', 'fragment'])
461
- expect(built.SchemaField).toBeTruthy()
462
- expect(typeof built.fragment.Field).toBe('function')
463
- })
464
-
465
- test('运行时:分类入参传组件 map,动态构造器按分类产出节点', () => {
466
- const { fragment: f } = createSchemaField({
467
- components: { Input: TypedInput },
468
- voidComponents: { Layout: TypedLayout },
469
- arrayComponents: { ArrayList: TypedArray },
470
- defaultDecorator: 'Layout',
471
- })
472
-
473
- expect(f.Field()()).toMatchObject({ type: 'string' })
474
- expect(f.Input({ title: '姓名' })()).toMatchObject({
475
- type: 'string',
476
- component: 'Input',
477
- title: '姓名',
478
- decorator: 'Layout',
479
- })
480
- expect(f.ArrayList(f.Input())()).toMatchObject({
481
- type: 'array',
482
- component: 'ArrayList',
483
- items: { type: 'string', component: 'Input' },
484
- })
485
- expect(f.Layout({})()).toMatchObject({ type: 'void', component: 'Layout' })
486
- expect(
487
- f.Object({
488
- name: f.Input({ required: true }),
489
- })()
490
- ).toMatchObject({ type: 'object', properties: { name: { type: 'string', component: 'Input' } } })
491
- })
492
-
493
- test('运行时:预绑定 SchemaField 无需再传 components 即可渲染 fragment 产出的 schema', () => {
494
- const { SchemaField: BoundSchemaField, fragment: f } = createSchemaField({
495
- components: { Input: TypedInput },
496
- arrayComponents: { ArrayList: TypedArray },
497
- })
498
- const schema = f.Object({ name: f.Input({ required: true }) })()
499
- const form = createForm()
500
-
501
- const view = mountWithForm(form, <BoundSchemaField schema={schema} />)
502
-
503
- expect(view.container.querySelector('input')).toBeTruthy()
504
- expect(form.fields['name']).toBeTruthy()
505
- })
506
-
507
- test('运行时:预绑定 SchemaField 支持 props 传扁平 map 覆盖同名组件', () => {
508
- function OverrideInput() {
509
- return <input className="override-input" />
510
- }
511
- const { SchemaField: BoundSchemaField, fragment: f } = createSchemaField({
512
- components: { Input: TypedInput },
513
- })
514
- const schema = f.Object({ name: f.Input() })()
515
- const form = createForm()
516
-
517
- const view = mountWithForm(form, <BoundSchemaField schema={schema} components={{ Input: OverrideInput }} />)
518
-
519
- expect(view.container.querySelector('.override-input')).toBeTruthy()
520
- })
521
-
522
- test('运行时:无参调用仍可用,动态构造器运行时保持宽松', () => {
523
- const { fragment: f } = createSchemaField()
524
- expect(f.Field()()).toMatchObject({ type: 'string' })
525
- expect((f as any).Anything()()).toMatchObject({ type: 'string', component: 'Anything' })
526
- })
527
-
528
- test('类型:组件 props、父子值类型与 scope 全部由扁平 components 推断,无需手写泛型', () => {
529
- const { fragment: f } = createSchemaField({
530
- components: demoComponents,
531
- voidComponents: { Layout: TypedLayout },
532
- arrayComponents: { ArrayList: TypedArray },
533
- scope: { $moment: (value: string) => value },
534
- })
535
-
536
- // @ts-expect-error 分类入参只接收组件 map,不再接收名字数组
537
- createSchemaField({ components: demoComponents, arrayComponents: ['ArrayList'] })
538
-
539
- f.Input({ componentProps: { maxLength: 10, placeholder: 'name' } })
540
- // @ts-expect-error componentProps 由组件 props 推导,maxLength 必须是 number
541
- f.Input({ componentProps: { maxLength: '10' } })
542
- // @ts-expect-error 未在 components 中声明的组件名不在类型表面
543
- void f.NotExist
544
-
545
- f.Object<{ name: string; age: number }>({
546
- name: f.Field({
547
- required: true,
548
- reactions: (field, scope) => {
549
- expectTypeOf(field.value).toEqualTypeOf<string>()
550
- expectTypeOf(scope.$moment).toEqualTypeOf<(value: string) => string>()
551
- expectTypeOf(scope.$record).toEqualTypeOf<{ name: string; age: number } & { $lookup: any; $index: number }>()
552
- },
553
- }),
554
- age: f.Field({
555
- required: true,
556
- reactions: field => {
557
- expectTypeOf(field.value).toEqualTypeOf<number>()
558
- },
559
- }),
560
- layout: f.Layout({}),
561
- })
562
-
563
- // @ts-expect-error 未在父级 record 中声明的 key 不允许产生值的字段,错误落在调用表达式上
564
- f.Object<{ name: string }>({
565
- name: f.Field({ required: true }),
566
- extra: f.Field(),
567
- })
568
-
569
- f.ArrayList(
570
- f.Object<{ name: string }>({
571
- name: f.Field({
572
- required: true,
573
- reactions: (_field, scope) => {
574
- expectTypeOf(scope.$record).toEqualTypeOf<{ name: string } & { $lookup: any; $index: number }>()
575
- },
576
- }),
577
- }),
578
- {
579
- reactions: (field, scope) => {
580
- expectTypeOf(field.value).toEqualTypeOf<{ name: string }[]>()
581
- expectTypeOf(scope.$moment).toEqualTypeOf<(value: string) => string>()
582
- },
583
- }
584
- )
585
- })
586
-
587
- test('类型:defaultDecorator 推断后收窄 decoratorProps', () => {
588
- const { fragment: f } = createSchemaField({
589
- components: { Input: TypedInput },
590
- voidComponents: { Layout: TypedLayout },
591
- defaultDecorator: 'Layout',
592
- })
593
-
594
- f.Input({ title: '姓名', decoratorProps: { colon: true } })
595
- // @ts-expect-error decoratorProps 按 Layout 的 props 推导
596
- f.Input({ title: '姓名', decoratorProps: { unknown: 1 } })
597
- })
598
- })
@@ -1,44 +0,0 @@
1
- import type { Form } from '@formvk/core'
2
- import { render } from '@testing-library/react'
3
- import type { RenderResult } from '@testing-library/react'
4
- import type { ReactNode } from 'react'
5
-
6
- import { FormProvider, useField } from '..'
7
-
8
- export function Input(props: any) {
9
- const field = useField()
10
- const { value, onChange, onFocus, onBlur, ...rest } = props
11
- // slots 是 React 适配层注入的具名插槽映射,不属于原生 input 属性
12
- delete rest.slots
13
- return (
14
- <input
15
- {...rest}
16
- className="input"
17
- data-testid={field?.path?.toString()}
18
- value={value ?? ''}
19
- onChange={event => onChange?.(event)}
20
- onFocus={event => onFocus?.(event)}
21
- onBlur={event => onBlur?.(event)}
22
- />
23
- )
24
- }
25
- Input.displayName = 'Input'
26
-
27
- export function Decorator(props: any) {
28
- return (
29
- <div className="decorator">
30
- {props.slots?.label}
31
- {props.children}
32
- </div>
33
- )
34
- }
35
- Decorator.displayName = 'Decorator'
36
-
37
- export function Container(props: any) {
38
- return <div className="container">{props.children}</div>
39
- }
40
- Container.displayName = 'Container'
41
-
42
- export function mountWithForm(form: Form, ui: ReactNode): RenderResult {
43
- return render(<FormProvider form={form}>{ui}</FormProvider>)
44
- }
@@ -1,16 +0,0 @@
1
- import { lazyMerge } from '@formvk/shared'
2
- import { useContext, useMemo } from 'react'
3
- import type { PropsWithChildren } from 'react'
4
-
5
- import { SchemaExpressionScopeContext } from '../shared/context'
6
- import type { IExpressionScopeProps } from '../types'
7
-
8
- /** 表达式作用域:与外层 scope 惰性合并,内层同名变量优先,Provider 天然隔离兄弟分支。 */
9
- export function ExpressionScope(props: PropsWithChildren<IExpressionScopeProps>) {
10
- const parentScope = useContext(SchemaExpressionScopeContext)
11
- const merged = useMemo(() => lazyMerge(parentScope ?? {}, props.value), [parentScope, props.value])
12
-
13
- return <SchemaExpressionScopeContext.Provider value={merged}>{props.children}</SchemaExpressionScopeContext.Provider>
14
- }
15
-
16
- ExpressionScope.displayName = 'ExpressionScope'
@@ -1,20 +0,0 @@
1
- import type { Form } from '@formvk/core'
2
- import { observer } from '@formvk/reactive-react'
3
- import type { ReactNode } from 'react'
4
-
5
- import { useForm } from '../hooks/useForm'
6
- import type { IFormConsumerRenderProps } from '../types'
7
-
8
- export interface IFormConsumerProps {
9
- children?: (renderProps: IFormConsumerRenderProps) => ReactNode
10
- }
11
-
12
- /** render props 形式读取 form,内部由 observer 追踪响应式状态,form 变化后自动刷新。 */
13
- export const FormConsumer = observer((props: IFormConsumerProps) => {
14
- const form = useForm()
15
- const { children } = props
16
- if (typeof children !== 'function') return null
17
- return children({ form: form as Form })
18
- })
19
-
20
- FormConsumer.displayName = 'FormConsumer'