Skip to content

Instantly share code, notes, and snippets.

@paambaati
Created Apr 12, 2020
Embed
What would you like to do?
react-select + react-hook-form
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