by franciscop · 7y ago · 0 comments
import forn from 'forn';
export default () => (
<form onSubmit={forn(data => console.log(data))}>
<input name="firstName" placeholder="First Name" />
<input name="lastName" placeholder="Last Name" />
<button>Send!</button>
</form>
);
Test it: https://codesandbox.io/s/agitated-johnson-3hv96Why do you need the register though? Is the hook needed to hold the refs? Is it only for compatibility with React Native or are there other reasons? With forn I use `e.target`, which should not be available in RN.
1. Support React controlled component. eg some of the popular component libs, they are wrapped input inside their component and it's hard to predict which to include during the form submit.
2. React Native <3
3. Attach validation rules, messages and async validation on the individual field level.
I'll try it next time I have to deal with React Native!