File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ ## list
2+
3+ <code src =" ../examples/list-unmount.tsx " ></code >
Original file line number Diff line number Diff line change 1+ import React , { useState } from 'react' ;
2+ import Form from 'rc-field-form' ;
3+ import Input from './components/Input' ;
4+ import LabelField from './components/LabelField' ;
5+
6+ const Demo = ( ) => {
7+ const [ form ] = Form . useForm ( ) ;
8+ const [ isShow , setIsShow ] = useState ( true ) ;
9+
10+ return (
11+ < div >
12+ < Form
13+ form = { form }
14+ onFinish = { values => {
15+ console . log ( JSON . stringify ( values , null , 2 ) ) ;
16+ console . log ( JSON . stringify ( form . getFieldsValue ( { strict : true } ) , null , 2 ) ) ;
17+ } }
18+ initialValues = { {
19+ users : [
20+ { name : 'a' , age : '1' } ,
21+ { name : 'b' , age : '2' } ,
22+ ] ,
23+ } }
24+ >
25+ < Form . Field shouldUpdate > { ( ) => JSON . stringify ( form . getFieldsValue ( ) , null , 2 ) } </ Form . Field >
26+
27+ < Form . List name = "users" >
28+ { fields => {
29+ return (
30+ < div >
31+ { fields . map ( field => (
32+ < div key = { field . key } style = { { display : 'flex' , gap : 10 } } >
33+ < LabelField name = { [ field . name , 'name' ] } >
34+ < Input />
35+ </ LabelField >
36+ { isShow && (
37+ < LabelField name = { [ field . name , 'age' ] } >
38+ < Input />
39+ </ LabelField >
40+ ) }
41+ </ div >
42+ ) ) }
43+ </ div >
44+ ) ;
45+ } }
46+ </ Form . List >
47+ < button type = "button" onClick = { ( ) => setIsShow ( c => ! c ) } >
48+ 隐藏
49+ </ button >
50+ < button type = "submit" > Submit</ button >
51+ </ Form >
52+ </ div >
53+ ) ;
54+ } ;
55+
56+ export default Demo ;
You can’t perform that action at this time.
0 commit comments