There is a Selector component of this form:
<Selector
initialSelectedOption={data[0].type}
onChange={(val) => changeValue(val.name)}
options={valueOptions}
/>;
when the user selects a value from the dropdown, onChange
is called and the value is updated in the selector.
I want to reset the value to the original one once the user has clicked cancel:
<Button onClick={handleCancel} />
...
const handleCancel = () => {
changeValue(data[0].type);
};
However, something is wrong here as it is not called.
Is it a way to call the Selector
's onChange
method from handleCancel
?
We need a bit more context to know for sure, but in general, you should define onChange
in a parent component and pass it as a prop to both the selector component and the component that handles the cancel.