react-native-select-pro
react-native-select-pro copied to clipboard
Data does not appear in the dropdown when state is updated
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:
- Do any API call and retrieve data in a useState
- Pass the getter constant of usestate into the select component
- The data will not be shown
Environment (please complete the following information):
- OS: Android
- OS Version: Android 13
- React Native Version : 0.72.4
- Google Pixel 3
Has this been resolved?
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: @.***>
I'm getting the same behavior. My list of options it's not updating after useEffect changes the state for the list.
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} />
Appreciated @jeferandom
Also having this problem, thank you for the workaround.
resolved: https://github.com/MobileReality/react-native-select-pro/pull/240