I want to make a dropdown but the picker in this code is not working. How the dropdown can be made? this code runs all other things like (Text etc) but when i add picker it gives an error. So, how to make dropdown then?
import { useState } from "react";
import { View, Picker, StyleSheet, Text} from "react-native";
export default function app() {
const [pickerval, setPickerval] = useState('java')
return(
<View style={styles.container}>
<Text>helo</Text>
<Picker style={styles.picker} selectedValue = {pickerval} onValueChange={(itemValue) => setPickerval(itemValue)} >
<Picker.Item label= "java" value= "java" />
<Picker.Item label= "a" value= "a" />
<Picker.Item label= "d" value= "d" />
</Picker>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}
})
2
Answers
Use this package,
import RNPickerSelect from ‘react-native-picker-select’;
Example code :
you can try this example, as per React Native Picker Guideline they removed Picker and moved to separate here