File size: 2,567 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
import React, { useState, useEffect } from 'react';
import ReactDOM from 'react-dom';
import { useForm } from 'react-hook-form';
import Input from '@material-ui/core/Input';
import Select from 'react-select';
import { Input as StrapInput } from 'reactstrap';
const options = [
{ value: 'chocolate', label: 'Chocolate' },
{ value: 'strawberry', label: 'Strawberry' },
{ value: 'vanilla', label: 'Vanilla' },
];
const MyInput = ({ name, label, register }) => {
return (
<>
<label htmlFor={name}>{label}</label>
<input name={name} placeholder="Jane" ref={register} />
</>
);
};
export default function App() {
const { register, handleSubmit, setValue } = useForm();
const onSubmit = (data) => {
alert(JSON.stringify(data, null));
};
const [values, setReactSelect] = useState({
selectedOption: [],
});
const handleMultiChange = (selectedOption) => {
setValue('reactSelect', selectedOption);
setReactSelect({ selectedOption });
};
useEffect(() => {
register({ name: 'reactSelect' });
}, []);
return (
<div className="App">
<form onSubmit={handleSubmit(onSubmit)}>
<div>
<Input
style={{
marginBottom: '20px',
}}
name="HelloWorld"
inputRef={register}
placeholder="Material UI - Input"
inputProps={{
'aria-label': 'Description',
}}
/>
</div>
<div>
<StrapInput
placeholder="Strap - Input"
name="strapInput"
innerRef={register}
/>
</div>
<div>
<label className="reactSelectLabel">React select</label>
<Select
className="reactSelect"
name="filters"
placeholder="Filters"
value={values.selectedOption}
options={options}
onChange={handleMultiChange}
isMulti
/>
</div>
<div>
<MyInput name="firstName" label="First Name" register={register} />
</div>
<div>
<label htmlFor="lastName">Last Name</label>
<input name="lastName" placeholder="Luo" ref={register} />
</div>
<div>
<label htmlFor="email">Email</label>
<input
name="email"
placeholder="bluebill1049@hotmail.com"
type="email"
ref={register}
/>
</div>
<button type="submit">Submit</button>
</form>
</div>
);
}
|