标题:React Native的优雅国家选择器:react-native-country-picker-modal
import React, { useState } from 'react';
import { View, Text, Button } from 'react-native';
import CountryPicker from 'react-native-country-picker';
const CountryPickerExample = () => {
const [selectedCountry, setSelectedCountry] = useState('');
return (
<View>
<CountryPicker
onValueChange={(value) => setSelectedCountry(value)}
selectedCountry={selectedCountry}
/>
<Button
title="选择国家"
onPress={() => alert(`您选择了: ${selectedCountry}`)}
/>
</View>
);
};
export default CountryPickerExample;
这个例子展示了如何在React Native应用中使用react-native-country-picker-modal
库来创建一个国家选择器,并在用户选择国家后弹出一个提示框显示选择的结果。这个例子简洁明了,并且使用了React Hooks来管理状态,这是目前在React Native中推荐的做法。
评论已关闭