i have two select menus. one that displays the names of the item types. It is of two types item1 and item2. and the other select menu lists the items for the selected type item1 or item2.
below is my code,
const App = () => {
const { item1Data } = fetchItem1Data;
const { item2Data } = fetchItem2Data;
const allData = (any)[] = [
...item1Data,
...item2Data,
]; //clubs both item1 and item2 data
const { item1typeData } = useQuery(item1typeData, {
variables: {
itemType: 'item1',
},
notifyOnNetworkStatusChange: true,
fetchPolicy: 'network-only',
});
const { item2typeData } = useQuery(item2type, {
variables: {
itemType: 'item2',
},
notifyOnNetworkStatusChange: true,
fetchPolicy: 'network-only',
});
const typesData: any = allData.map((data: any) => {
return {
label: data.name,
value: data.id,
};
});
const itemData = [];
return (
<Select
onChange={(option: SelectOption) =>
form.setFieldValue(field.name, option.value)
}
options={typesData}
placeholder="Select"
value={typesData.filter(option => option.value === field.value)}
/>
<Select
options={itemData}
placeholder="Select items"
value={}
onChange={}
/>
as you see in above code the second select menu doesnt have options. i want to have options for that menu based on the type selected in first select menu.
so basically when user selects one option from first select menu we need to check its type.
if type selected is item1 then i need to set itemData to item1typeData. if type selected is item2 then i need to set itemData to item2typeData. else [];
also for allData when combining both item1Data and item2Data i need to map through each item and add its type say 'item1' for item1Data and 'item2' for 'item2Data'.
how can i do it. could someone help me do it using react and typescript.