import React, { useState } from 'react'; import { View, Text, TouchableOpacity } from 'react-native'; import { AutoComplete, AutoCompleteOption } from '@xrnjs/ui'; import styles from './style'; const ControlledDemo = () => { const [value, setValue] = useState(''); const [options] = useState([ { value: '预设选项1' }, { value: '预设选项2' }, { value: '预设选项3' }, ]); const handleChange = (newValue: string) => { setValue(newValue); console.log('受控组件值变化:', newValue); }; const handleClear = () => { setValue(''); }; const handleSetValue = () => { setValue('程序设置的值'); }; return ( 受控组件 设置值 清空 通过 value 和 onChange 控制组件状态 当前值: {value || '(空)'} ); }; export default ControlledDemo;