1import React from 'react';
2import ReactDOM from 'react-dom';
3import { connect } from "react-redux";
4import useForm from 'react-hook-form';
5
6function SampleForm() {
7 const { register, handleSubmit } = useForm();
8 const onSubmit = data => {
9 alert(JSON.stringify(data));
10 };
11
12 return (
13 <div className="App">
14 <form onSubmit={handleSubmit(onSubmit)}>
15 <div>
16 <label htmlFor="firstName">First Name</label>
17 <input name="firstName" placeholder="bill" ref={register} />
18 </div>
19
20 <div>
21 <label htmlFor="lastName">Last Name</label>
22 <input name="lastName" placeholder="luo" ref={register} />
23 </div>
24
25 <div>
26 <label htmlFor="email">Email</label>
27 <input name="email" placeholder="bluebill1049@hotmail.com" type="email" ref={register} />
28 </div>
29 <button type="submit">Submit</button>
30 </form>
31 </div>
32 );
33}
34
35class Sample extends Component {
36 constructor(props) {
37 super(props);
38 }
39
40 render() {
41 return <SampleForm />;
42 }
43}
44
45export default connect()(Sample);
46
47const rootElement = document.getElementById('root');
48ReactDOM.render(<Sample />, rootElement);