3 ms·
This looks really good. But is there a non-hook version for use in class components? I'm imagining it might look like this: class MyForm extends React.Comp
by CGamesPlay 7y ago
This looks really good. But is there a non-hook version for use in class components? I'm imagining it might look like this:
class MyForm extends React.Component {
formState = new ReduxHookForm();
render() {
const { register, handleSubmit } = this.formState;
return (
<form onSubmit={handleSubmit(this.handleSubmit)}>
<input name="firstName" ref={register} />
<select name="gender" ref={register}>
<option value="male">male</option>
<option value="female">female</option>
</select>
<input type="submit" />
</form>
);
}
handleSubmit(data) {
console.log(data);
}
}
- bluebill1049 7y agoyea would be similar for class component :)
- CGamesPlay 7y agoSorry I don't understand. Last time I checked, hooks are not usable from class components. How can I use react-hook-form from a class component?
- bluebill1049 7y agoSorry I meant once I made it work, and it will be the syntax
- bluebill1049 7y agoI haven't got a plan to look into class component just yet, but will do in the near future.
- franciscop 7y agoI have a pure-javascript library that works like that, "forn". No hooks or any local state needed: https://www.npmjs.com/package/forn https://www.npmjs.com/package/forn
- ozgrozer 7y agoI made this one last year. It can be used with class components too. https://github.com/ozgrozer/rfv https://github.com/ozgrozer/rfv