i have a component child that is used in create and edit mode. it has select menu that displays no value until user selects an option from select menu in create mode.
in edit mode, this select menu should show the previously selected option.
below is my code,
const Child = (mode: mode, formikBag: formikBag) => {
const handleValue = (field) => {
if (mode === 'edit') {
const selectedId = formikBag.values[itemId];
const selectedItems = allItems.filter((item) => item.id ===
itemId;
return selectedItem[0].name;
}
return allItems.filter((option) => option.value === field.value);
//should be returned in create mode
return(
<Select
value={handleValue}
/>
);
}
the above code doesnt show any value in edit or create mode. not sure what is going wrong. i am new to react.
could someone help me with this. thanks.
value={() => handleValue('fieldName')}?