forked from stuburger/yafl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleForm.tsx
47 lines (42 loc) · 862 Bytes
/
SimpleForm.tsx
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
import * as React from 'react'
import { createFormContext } from './src/form'
interface Guy {
name: string
friends: Array<Guy>
}
const { Form, Field, FieldMap } = createFormContext<Guy>({ name: '', friends: [] })
const GuyFields = props => {
return (
<>
<Field
name="name"
parent={props.parent}
render={({ input, ...props }) => <TextInput {...input} />}
/>
<FieldMap
name="friends"
parent={props.parent}
render={props => {
return <GuyFields {...props} />
}}
/>
</>
)
}
class SimpleForm extends React.Component<any> {
render() {
return (
<Form>
<GuyFields />
</Form>
)
}
}
function TextInput(props) {
return (
<div>
<label>{props.forwardProps.label}</label>
<input {...props.input} />
</div>
)
}