-
-
Notifications
You must be signed in to change notification settings - Fork 279
Expand file tree
/
Copy pathinitialValues.tsx
More file actions
67 lines (62 loc) · 1.78 KB
/
initialValues.tsx
File metadata and controls
67 lines (62 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* eslint-disable react/prop-types */
import React, { useState } from 'react';
import Form from 'rc-field-form';
import Input from './components/Input';
const { Field, List } = Form;
const formValue = {
test: "test",
users: [{ first: "aaa", last: "bbb" }]
};
export default () => {
const [form] = Form.useForm<typeof formValue>();
const [show, setShow] = useState<boolean>(false);
return (
<>
<button onClick={() => setShow((prev) => !prev)}>switch show</button>
{show && (
<Form
form={form}
initialValues={formValue}
preserve={false}
onFinish={values => {
console.log('Submit:', values);
}}
>
<Field shouldUpdate>
{() => (
<Field name="test" preserve={false}>
<Input/>
</Field>
)}
</Field>
<List name="users">
{(fields) => (
<>
{fields.map(({ key, name, ...restField }) => (
<>
<Field
{...restField}
name={[name, "first"]}
rules={[
{ required: true, message: "Missing first name" }
]}
>
<Input placeholder="First Name" />
</Field>
<Field
{...restField}
name={[name, "last"]}
rules={[{ required: true, message: "Missing last name" }]}
>
<Input placeholder="Last Name" />
</Field>
</>
))}
</>
)}
</List>
</Form>
)}
</>
);
};