If you need to trigger a form submission from a component located outside the <Form> tree, you can use one of the following methods:
1. Use the HTML form attribute
Assign an id to your <form> and reference that ID in the form attribute of your submit button.
2. Dispatch a DOM event
Use document.getElementById() to find the form and dispatch a submit event. Note: Do not use .submit(), as it will not trigger React's event handlers. You must use dispatchEvent with a cancelable, bubbling event.
3. Use a Closure
Capture the handleSubmit function provided by the render prop in a variable defined in an outer scope. To ensure the closure is correctly updated, call the function via an arrow function in the button's onClick handler.
4. Redux Dead Drop
If using Redux, you can implement the Redux Dead Drop pattern.
// Method 1: HTML form attribute
<button type="submit" form="myForm">Submit</button>
<form id="myForm" onSubmit={handleSubmit}>
...fields go here...
</form>
// Method 2: Dispatching DOM event
<button onClick={() => {
document.getElementById('myForm')
.dispatchEvent(new Event('submit', { cancelable: true, bubbles:true })) // ✅
}}>Submit</button>
// Method 3: Via Closure
let submit
return (
<div>
<button onClick={event => submit(event)}>Submit</button> // ✅
<Form
onSubmit={onSubmit}
render={({ handleSubmit }) => {
submit = handleSubmit
return <form>...fields go here...</form>
}}
/>
</div>
)