React native 取消Bouncing搜索输入onChangeText()
使用lodash的React native 取消Bouncing搜索输入onChangeText(),react-native,lodash,debouncing,React Native,Lodash,Debouncing,使用lodash的debounce()。但当我使用它时,它似乎没有运行我的函数: onChangeText(text) { console.log('setting'); setSearching(true); setSearchTerm(text); } render(){ return( <TextInput style={s.input} onChangeText={() => {
debounce()。但当我使用它时,它似乎没有运行我的函数:
onChangeText(text) {
console.log('setting');
setSearching(true);
setSearchTerm(text);
}
render(){
return(
<TextInput style={s.input}
onChangeText={() => {
_.debounce(this.onChangeText, 1200);
/*
doing just...
this.onChangeText(text)
...works
*/
}}
/>
)
}
onChangeText(文本){
console.log('setting');
设置搜索(真);
设置搜索项(文本);
}
render(){
返回(
{
_.debounce(此.onChangeText,1200);
/*
正在做的只是。。。
此.onChangeText(文本)
作品
*/
}}
/>
)
}
使用debounce
时,我的控制台日志中没有设置。有什么想法吗?现在,您正在为处理程序的每次调用创建一个新的debounce
实例
理想情况下,您应该将整个处理程序包装在debounce
中,因为debounce会创建一个debounced
函数来延迟调用func
现在,在处理程序的每次调用中,您都要创建一个新的debounce
实例
理想情况下,您应该将整个处理程序包装在debounce
中,因为debounce会创建一个debounced
函数来延迟调用func
这是可行的,但如何调用setsearch(true)代码>在去盎司之前?不确定,但您可能需要在函数内部使用debounce
,仅用于setSearchTerm
函数。\uBounce(()=>searchTerm(text),1200)
这是有效的,但我如何调用setSearching(true)代码>在解盎司之前?不确定,但您可能需要在函数内部使用debounce
,仅用于setSearchTerm
函数。\debounce(()=>searchTerm(text),1200)
onChangeText={_.debounce(this.onChangeText, 1200)}