Simply convert a form submit event to a Javascript object
Simply convert a form submit event to a Javascript object
name="values.0.name"
will be converted as { values: [{ name }] }
)fromEvent(event: SubmitEvent, starter: Object): Object
: convert the submit event ̀event
to a Javascript object
name
attribute for this to workstarter
object, in which case this object will be copied and then populated with the form informationswrapSubmit(callback: Function, starter: Object): Function
: wrap your implementation before giving it to your "submit" callback form
callback(data: object, event: window.Event): void
fromEvent
import React from 'react'
import { fromEvent } from 'from-form-submit'
const Component = () => (
<form
onSubmit={(event) => {
console.log(fromEvent(event))
}}
>
<input type="number" name="age" />
<input type="string" name="name" />
</form>
)
wrapSubmit
import React from 'react'
import { wrapSubmit } from 'from-form-submit'
const Component = () => (
<form onSubmit={wrapSubmit(console.log)}>
<input type="number" name="age" />
<input type="string" name="name" />
</form>
)