Typescript error for options prop #5049
Answered
by
Methuselah96
brunolsantos
asked this question in
Q&A
-
I'm using Types.ts file export interface DropdownFilterProps {
dropdowns: [
{
options: DropdownOption[];
id: string;
setSelected?: Function;
}
];
}
export interface DropdownOption {
value: string;
label: string;
} Select.tsx import React, { useState, useEffect } from 'react';
import Select from 'react-select';
import { DropdownFilterProps } from './types';
export function DropdownFilter({ dropdowns }: DropdownFilterProps) {
const [selectedItems, setSelectedItems] = useState<any>(null);
useEffect(() => {
...
};
const setSelectedItemToState = (selectedDropdownOption: any) => {
...
};
return (
<div>
{dropdowns &&
dropdowns.map((item) => {
return (
<Select
value={() => getSelectedValue(item.id)}
options={item.options}
onChange={(selectedOption) => {
setSelectedItemToState(selectedOption);
}}
/>
);
})}
</div>
);
} And i get below error for options prop
Can someone please add an example of typescript usage for Package.json
|
Beta Was this translation helpful? Give feedback.
Answered by
Methuselah96
Feb 8, 2022
Replies: 1 comment 1 reply
-
That's because the {dropdowns &&
dropdowns.map((item) => {
return (
<Select
- value={() => getSelectedValue(item.id)}
+ value={getSelectedValue(item.id)}
options={item.options}
onChange={(selectedOption) => {
setSelectedItemToState(selectedOption);
}}
/>
);
})} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
brunolsantos
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's because the
value
prop needs to take an option not a function. Maybe this is what you're trying to do? Note thatgetSelectedValue
would need to return aDropdownOption
.