【发布时间】:2021-04-16 21:42:24
【问题描述】:
我在下面有这段代码,我想在 SearchBarCustom 组件中传递 onchange={handleTextChange}。但是,如果我删除 onChangeText={setValue} 并在 SearchBarCustom 组件中添加 onchange={handleTextChange},我将无法在搜索栏中输入任何内容。如何传入handleTextChange?
const SearchScreen = ({}: StackNavigationProps<Routes, "SearchScreen">) => {
const SearchBarCustom = (props) => {
const [value, setValue] = useState('');
return <SearchBar value={value} onChangeText={setValue} {...props} />;
};
return (
<ScrollView style={styles.container} contentInsetAdjustmentBehavior='automatic' stickyHeaderIndices={[0]}>
<View>
<GoogleAutoComplete apiKey={apiKey} debounce={500} minLength={1} queryTypes={'(cities)'} >
{({ handleTextChange, locationResults}) => (
<React.Fragment>
<View style={styles.inputWrapper}>
<SearchBarCustom
onChangeText={handleTextChange} // ???
containerStyle={{ backgroundColor: '#f3f2f8'}}
inputContainerStyle={{ backgroundColor: '#e3e3e9', height: 30}}
placeholderTextColor = '#96969b'
placeholder="Search"
platform="ios"
/>
</View>
<ScrollView>
{locationResults.map(el => (
<LocationItem
{ ...el}
key={el.id}
/>
))}
</ScrollView>
</React.Fragment>
)}
</GoogleAutoComplete>
</View>
</ScrollView>
);
};
【问题讨论】:
标签: javascript typescript react-native expo