danish1658 / react-native-dropdown-select-list

☝️ React Native Select List Equivalent to Html's Select with options"
https://www.npmjs.com/package/react-native-dropdown-select-list
MIT License
207 stars 96 forks source link

Reset to empty select option #18

Closed poinch closed 1 year ago

poinch commented 2 years ago

Hi there,

i'll try to explain the issue i'm facing at the moment. I'm using the Select list in this way:

<SelectList data={dropDownBuyableGiftCards} setSelected={(id: string) => selectGiftCardAmountHandler(id)} placeholder="Scegli il valore" search={false} boxStyles={styles.dropdown} inputStyles={styles.dropdownText} dropdownStyles={styles.dropdownItemsContainer} dropdownTextStyles={styles.dropdownText} defaultOption={{ key: null, value: null }} />

where selectGiftCardAmountHandler it's a function that dispatch a action to a reducer:

const selectGiftCardAmountHandler = (id: string) => { const giftCardToBuy = buyableGiftCards.find((buyableGiftCard) => buyableGiftCard.id === id); dispatch(addGiftCardAmountToBuy({ id: giftCardToBuy.id, amount: giftCardToBuy.voucher.gift.amount })); };

Everything looks good, after the purchase of the gift card mentioned in my code i will go back to my home page and then if i go back to the gift card section the previous values are still selected BUT if i go back again and enter the gift card again the values will reset.

Looks like needs 2 re render to reset. I also have a: useEffect(() => { (async () => { const buyableGiftCards = await getBuyableGiftCards(); dispatch(addBuyableGiftCards(buyableGiftCards)); })(); dispatch(resetGiftCardToBuy()); }, [giftcardToBuy]);

where resetGiftCardToBuy reset all my data selected but i don't think this will help.

Anyone could help please

danish1658 commented 2 years ago

Thanks for raising this issue, i understood the rendering issue and will fix this in upcoming version

poinch commented 2 years ago

@danish1658 Thank you, appreciate it

MohanNaidu69 commented 2 years ago

I think I am also facing the same issue, not able to reset the dropdown to its initial and original view. I have a form after submitting I want to reset the dropdown to its original view. Please help by fixing this issue. Appreciate the work... Thanks in Advance.

danish1658 commented 2 years ago

@MohanNaidu69 Version 2.0 is ready , This issue has been resolved in new version , expect an update anytime soon

danish1658 commented 1 year ago

v2 is out now , see if issue is fixed , if not you can reopen this issue