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
200 stars 89 forks source link

setSelected is called on the initial mounting of component #33

Closed shamar-morrison closed 1 year ago

shamar-morrison commented 1 year ago

Hello there,

When this component is initially mounted the setSelected function is executed. Is this how it is supposed to behave?

I believe the setSelected function should only execute whenever the user selects a new option from the dropdown since this function is currently the only way to get the selected value. Having it run on mount leads to some nasty bugs.

Thank you!

danish1658 commented 1 year ago

Please let me know your package version

shamar-morrison commented 1 year ago

"react-native-dropdown-select-list": "^2.0.2"

RadAd commented 1 year ago

I'm seeing this behaviour also. "react-native-dropdown-select-list": "^2.0.4"

RadAd commented 1 year ago

In this section:

React.useEffect(() => {
        if(!_firstRender && defaultOption && oldOption.current != defaultOption.key ){
            // oldOption.current != null
            oldOption.current = defaultOption.key
            setSelected(defaultOption.key);
            setSelectedVal(defaultOption.value);
        }
        if(defaultOption && _firstRender && defaultOption.key != undefined){
            oldOption.current = defaultOption.key
            setSelected(defaultOption.key);
            setSelectedVal(defaultOption.value);
        }
    },[defaultOption])

I think you should remove the call to setSelected. They are not respecting the save property either.

LayMui commented 1 year ago

thank RadAd this fixed the issue

danish1658 commented 1 year ago

Has been fixed in new version, please wait for update