I am trying to create an example component that uses react-select with typescript.
For this, I created a functional component and added the default example from react-select docs:
const options = [
{value: 'chocolate', label: 'Chocolate'},
{value: 'strawberry', label: 'Strawberry'},
{value: 'vanilla', label: 'Vanilla'},
];
const MyComponent = () => {
const [selectedOption, setSelectedOption] = useState('chocolate');
const handleChange = (option: string) => {
setSelectedOption(option);
};
return (
<Select
value={selectedOption}
onChange={(option) => handleChange(option)}
options={options}
/>
);
};
However, this gives me an error:
Overload 1 of 2, '(props: Readonly<Pick<Props<OptionTypeBase>, string | number> & Props<OptionTypeBase> & Props<OptionTypeBase>>): StateManager<...>', gave the following error.
Type 'string' is not assignable to type 'ValueType<OptionTypeBase>'.
Overload 2 of 2, '(props: Pick<Props<OptionTypeBase>, string | number> & Props<OptionTypeBase> & Props<OptionTypeBase>, context?: any): StateManager<...>', gave the following error.
Type 'string' is not assignable to type 'ValueType<OptionTypeBase>'.
what am I doing wrong?
My packages are:
"@types/react": "^16.9.19",
"@types/react-dom": "^16.9.5",
"@types/react-select": "^3.0.10",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-select": "^3.0.8",
"typescript": "^3.7.5"