-
-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathField.js
More file actions
67 lines (63 loc) · 1.22 KB
/
Field.js
File metadata and controls
67 lines (63 loc) · 1.22 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
// @flow
import * as React from 'react'
import type { FieldProps as Props, FieldRenderProps } from './types'
import renderComponent from './renderComponent'
import useField from './useField'
const Field = ({
afterSubmit,
allowNull,
beforeSubmit,
children,
component,
data,
defaultValue,
format,
formatOnBlur,
initialValue,
isEqual,
keepFieldStateOnUnmount,
multiple,
name,
parse,
subscription,
type,
validate,
validateFields,
value,
...rest
}: Props) => {
const field: FieldRenderProps = useField(name, {
afterSubmit,
allowNull,
beforeSubmit,
children,
component,
data,
defaultValue,
format,
formatOnBlur,
initialValue,
isEqual,
keepFieldStateOnUnmount,
multiple,
parse,
subscription,
type,
validate,
validateFields,
value
})
if (typeof children === 'function') {
return (children: Function)({ ...field, ...rest })
}
if (typeof component === 'string') {
// ignore meta, combine input with any other props
return React.createElement(component, { ...field.input, children, ...rest })
}
return renderComponent(
{ children, component, ...rest },
field,
`Field(${name})`
)
}
export default Field