Reset Select selected value #1808
-
I'm opening this thread to discussion how to reset the selected value of a select when the collection changes. The use case is this: I have a collection that is derived from a selected ID that can change. So depending on the selected ID I'll have different collections. The thing is that if the user select an item from collection 1, then changes the ID (obtaining collection 2) the selected value isn't cleared. Don't know if this behaviour should be included in the core of the select library, but currently there's no way to do it. Eventually we can manually listen for collection changes in a useEffect, the problem is that with react strict mode this don't work, so I don't really know how to achieve this. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Based on my understanding of your use case, I recommend explicitly changing the collection when the id changes. Here's an example: |
Beta Was this translation helpful? Give feedback.
Based on my understanding of your use case, I recommend explicitly changing the collection when the id changes.
Here's an example:
https://stackblitz.com/edit/vitejs-vite-mhintx?file=src%2FApp.tsx&terminal=dev