MobileReality / react-native-select-pro

React Native dropdown (select) component developed by Mobile Reality
https://mobilereality.github.io/react-native-select-pro
MIT License
280 stars 18 forks source link

Data does not appear in the dropdown when state is updated #237

Closed hunzalaqamar closed 3 months ago

hunzalaqamar commented 9 months ago

Describe the bug the data in the dropdown is not being shown after the API call and the usestate gets updated

To Reproduce Steps to reproduce the behavior:

  1. Do any API call and retrieve data in a useState
  2. Pass the getter constant of usestate into the select component
  3. The data will not be shown

Environment (please complete the following information):

kyagie commented 6 months ago

Has this been resolved?

hunzalaqamar commented 6 months ago

I didn't check it again but i found a runaround for it. I re-render the component manually everytime the state is updated and that is how I'm able to show new data in it.

On Sun, Mar 10, 2024, 14:32 Arthur Kirabo @.***> wrote:

Has this been resolved?

— Reply to this email directly, view it on GitHub https://github.com/MobileReality/react-native-select-pro/issues/237#issuecomment-1987159489, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQPTZBS4ZQANYUT3JHAEADLYXQSBXAVCNFSM6AAAAABA5HZ5PSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBXGE2TSNBYHE . You are receiving this because you authored the thread.Message ID: @.***>

jeferandom commented 4 months ago

I'm getting the same behavior. My list of options it's not updating after useEffect changes the state for the list.

jeferandom commented 4 months ago

This is my code to re-render if helps to anyone facing same issue. Thanks to @hunzalaqamar for the workaround suggestion.

const [renderKey, setRenderKey] = useState(0);

useEffect(() => {

//update my list of options code here
    ...

    setRenderKey(prevKey => prevKey + 1);
  }, []);

  <Select key={renderKey} options={cropsList} theme={"dark"} styles={styles} />
hunzalaqamar commented 4 months ago

Appreciated @jeferandom

0afcode commented 3 months ago

Also having this problem, thank you for the workaround.

dawidgierdal commented 3 months ago

resolved: https://github.com/MobileReality/react-native-select-pro/pull/240

LucasHimelfarb commented 1 week ago

@dawidgierdal

the new prop reinitializeOptions is not working properly if you've a Select with searchable prop enabled.

and the trick key={renderKey} produce a new render, that's causes the loss of input focus