react-native-paper-dropdown
react-native-paper-dropdown copied to clipboard
Default value
Hi, How I set a default value? Thanks!
I don't know if it is the best way or not, but I think I could share this because it is work for me
Open the file /node_modules/react-native-paper-dropdown/dist/DropDown.js
and add this code right after displayValue
state declaration
useEffect(() => {
if (value != null) {
list.map(l => {
if (l.value == value) {
setDisplayValue(l.label);
}
})
}
}, [displayValue, setDisplayValue, value]);
Now when your value
prop is same with any value of your list
, displayValue
will replaced with the matched value in your list.
I hope this could help you immediately, and sorry if this is not the best way to write due to I'm not expert in JS and React. And we all wish creator would add this feature soon
Made a PR for this: #75
Let's see if the maintainer can review and merge, this package has not been updated in over a year.