Created
April 12, 2020 10:40
-
-
Save paambaati/ac72a90df09481b7f4424ae1d878dacf to your computer and use it in GitHub Desktop.
react-select + react-hook-form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { forwardRef } from 'react'; | |
import Select from 'react-select'; | |
import { Controller } from 'react-hook-form'; | |
import type { RefObject } from 'react'; | |
import type { Props as ReactSelectProps } from 'react-select'; | |
const Select = forwardRef( | |
(props: SelectProps, ref: RefObject<HTMLSelectElement>) => { | |
return ( | |
<Controller | |
ref={ref} | |
as={<Select options={props.options} />} | |
onChange={([selected]) => { | |
console.log('selected = ', selected); | |
return selected; | |
}} | |
{...props} | |
/> | |
); | |
} | |
); | |
export type SelectProps = ReactSelectProps & { | |
controllerProps?: any; | |
}; | |
export default Select; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment