import React, { useRef, useState } from 'react'; import { View, Text, TouchableOpacity } from 'react-native'; import { AutoComplete, AutoCompleteOption, AutoCompleteRef } from '@xrnjs/ui'; import styles from './style'; const RefDemo = () => { const autoCompleteRef = useRef(null); const [options, setOptions] = useState([]); const handleChange = (value: string) => { if (!value) return setOptions([]); const suggestions = Array.from({ length: 5 }, (_, i) => ({ value: `${value}_ref选项${i + 1}`, })); setOptions(suggestions); }; const handleFocus = () => { autoCompleteRef.current?.focus(); }; const handleBlur = () => { autoCompleteRef.current?.blur(); }; const handleClear = () => { autoCompleteRef.current?.clear(); }; return ( Ref 使用 聚焦 失焦 清空 通过 ref 可以调用组件的方法 ); }; export default RefDemo;