react select with react hook form cotroller

Solutions on MaxInterview for react select with react hook form cotroller by the best coders in the world

showing results for - "react select with react hook form cotroller"
Maria
09 Sep 2016
1function Yourcomponent(props){
2
3    const methods = useForm();
4    const { handleSubmit } = methods;
5    
6
7    const options = [
8     { value: '1', label: 'Apple'},
9     { value: '2', label: 'Ball'},
10     { value: '3', label: 'Cat'},
11    ];
12    
13    const default_value = 1; // you can replace with your default value
14    
15
16    // other codes of the component 
17    
18
19    function submitHandler(formData){
20    
21    // values are available in formData
22
23    }
24
25
26    return(
27      <div>
28        
29        {* other part of your component *}
30        <form onSubmit={handleSubmit(submitHandler)} >
31
32           {* other part of your form *}
33            <Controller
34                control={methods.control}
35                defaultValue={default_value}
36                name="field_name_product"
37                render={({ onChange, value, name, ref }) => (
38                    <Select
39                        inputRef={ref}
40                        classNamePrefix="addl-class"
41                        options={options}
42                        value={options.find(c => c.value === value)}
43                        onChange={val => onChange(val.value)}
44                    />
45                )}
46            />
47
48           {* other part of your form *}
49        </form>
50
51        {* other part of your component *}
52      </div>
53    )
54}
55
queries leading to this page
asycn react select with react hook form controllerreact hook form react select registeruse form hook with react selectselect react hook formreact hook form with react selectreact hook form select optionreact hook form onchange for selectreact native hook form selectreact select in react hook formreact hook form selectionreact select with hook formcontroller react hook form react select typescriptreact hook form controller selectselect field in react hook formselect option react hook formreact form hook with react selectreact hook form select controllerreact hook form select optionsmaterial ui select react hook form controllerreact hook form select valuereact select react hook formreact select with hook formcontroller react hook form react selectreact select and react hook formreact select react hook formreact hook form select onchangeuseform controller react selectreact select with react hook formwork with select react hook formreact hook form typescriptreactjs hook forms controller select examplereact js hook form select optionsreact hook form with onselect react select createable and react hook form controllerselect react hook form itemreact form select hookreact hook form selecthow to use react select as controller react hook formsreact select with react hook form cotrollerhow to use select using react hook formreact select react hooks formreact select 22react hook form 22react select creatable with react hook formreact form hook selectreact select with react hook formreact hook forms select onchangereact hook form onchange on selectreact hook form select options valiatereact hook form controller select valueselect form react hooksselect in react js in hook formreact hook form select option choosereact hook form with selectselect option choose react hook forms controller react hook form select styleselect with react hook formreact hook form and react selectreact hook form select dispatchreact hook form handling selectselect onchange react hook formreact form hook and react selectselect dropdown in react hook formreact select register with react hook formreact hook form select box examplecontroller select react hook formreact select onsubmit react hook formreact hook form select from on to trueuse react hook form with react selectreact hook form setvalue for selectreact hook form setvalue select material uihook form react selectreact hook form controlled selectreact hook form controller select onchangereact hook form onchange selectreact select with react hook form examplereact hook form select examplereact hook form material ui controller selectcontroller react hook form selectreact select react hook form 7option select react hook formreact select hook form controllerreact hook form react selectreact select with react hook form cotroller