Parth Khatri
Parth Khatri

Reputation: 122

How can i reset child dropdown when parent down has been changed?

Here is full demo what i want to say..

when I select android than it gives options of android and when I change option to apple than old option already select how can I unselect them. Any idea ?

DEMO

Upvotes: 1

Views: 481

Answers (1)

fullstack
fullstack

Reputation: 834

You can keep the values of the inner selects in a variables, and reset them when the outer select changes.

const [left, setLeft] = useState();
const [right, setRight] = useState();

and then, use this values like this:

<Select
   placeholder="Minimum OS version"
   options={
      selectedPlatform === "IOS" ? iosVersions : androidVersions
   }
   onChange={(e: any) => setLeft(e)}
   value={left}        
/>

and in the onChange of the outer select do:

setLeft(null);
setRight(null);

Upvotes: 1

Related Questions