Skip to content

Commit cec82b3

Browse files
committed
feat: test
1 parent 673536c commit cec82b3

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

docs/demo/list-unmount.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## list
2+
3+
<code src="../examples/list-unmount.tsx"></code>

docs/examples/list-unmount.tsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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;

0 commit comments

Comments
 (0)