I am trying to create custom components for DropdownIndicator and use on react-select with Typescript, but I am having some issues with the type of the component because I am new to typescript.
How can I use types defined on @types/react-select on my component?
I've installed @types/react-select and there is already a type for DropdownIndicator, but I've found no way to reference it.
This is my index.tsx:
import React from 'react';
import Select from 'react-select';
import DropdownIndicator from './dropdown-indicator';
const components = {
DropdownIndicator,
};
const SelectFilter: React.FC = () => {
return <Select components={components} />;
};
export default React.memo(SelectFilter);
This is my dropdown-indicator.tsx:
import React from 'react';
import DropdownIcon from './dropdown-icon';
const DropdownIndicator: React.FC = props => {
const {
selectProps: { isMenuOpen },
} = props;
return <DropdownIcon isUp={isMenuOpen} />;
};
export default React.memo(DropdownIndicator);
Since I didn't defined any prop types, the error is:
/Users/felipepinheiro/Workspace/test/src/components/select-filter/dropdown-indicator.tsx
TypeScript error in /Users/felipepinheiro/Workspace/test/src/components/select-filter/dropdown-indicator.tsx(7,5):
Property 'selectProps' does not exist on type '{ children?: ReactNode; }'. TS2339
5 | const DropdownIndicator: React.FC = props => {
6 | const {
> 7 | selectProps: { isMenuOpen },
| ^
8 | } = props;
9 |
10 | return <DropdownIcon isUp={isMenuOpen} />;
props.selectProps.menuIsOpennotisMenuOpen;) and do not destruct them.ts import {IndicatorProps } from 'react-select'; const SelectFilter: React.FC = () => { return <Select components={{ Indicator: (indicatorProps: IndicatorProps<any>) => ( <components.DropdownIndicator {...indicatorProps} /> ), }} />; };