-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathForm.js
42 lines (34 loc) · 1003 Bytes
/
Form.js
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
// @flow
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { withReduxForm } from './ReduxFormContext'
import type { ReactContext } from './types'
export type Props = {
onSubmit: Function
}
type PropsWithContext = ReactContext & Props
class Form extends Component<PropsWithContext> {
constructor(props: PropsWithContext) {
super(props)
if (!props._reduxForm) {
throw new Error('Form must be inside a component decorated with reduxForm()')
}
}
componentDidMount() {
this.props._reduxForm.registerInnerOnSubmit(this.props.onSubmit)
}
componentDidUpdate(prevProps: Props) {
if (this.props.onSubmit !== prevProps.onSubmit) {
this.props._reduxForm.registerInnerOnSubmit(this.props.onSubmit)
}
}
render() {
const { _reduxForm, ...rest } = this.props
return <form {...rest} />
}
}
Form.propTypes = {
onSubmit: PropTypes.func.isRequired,
_reduxForm: PropTypes.object
}
export default withReduxForm(Form)