Handle submit
Provide the action prop to handle a submit of a Form component.
1
import React from 'react'
2
import { Form } from 'react-advanced-form'
3
4
export default class ExampleForm extends React.Component {
5
render() {
6
return (
7
<Form action={this.registerUser}>
8
{/* ... */}
9
</Form>
10
)
11
}
12
}
Copied!
The action prop expects a function which returns a Promise. By returning the latter Form can properly react to the Promise status, which is a submit request status at the same time.
1
import React from 'react'
2
import { Form } from 'react-advanced-form'
3
4
export default class ExampleForm extends React.Component {
5
registerUser = ({ serialized, fields, form }) => {
6
return fetch(API_URL, {
7
method: 'POST',
8
body: JSON.stringify(serialized),
9
})
10
}
11
12
render() {
13
return (
14
<Form action={this.registerUser}>
15
{/* ... */}
16
</Form>
17
)
18
}
19
}
Copied!
Read more about the action prop.
Last modified 3yr ago
Copy link