Dec 3, 2020
0
Level 8
React Native: lodash debounce not working?
Hi everybody, in my react native app I have a textinput for users to type and search, I want to use lodash debounce so that the automatice search is more performant but for some reason my results array is never populated and I'm not console login anything either...
Funny thing is if instead of changing state inside debounce action I change results array without debouncing it actually works right but doing a search each key change seems like a lot, is it? I'm not doing fetches but a javascript search which would be better performance wise.
Here is my code:
const handleSearchChange = (value)=>
{
setSearch(value);
let results = filterSearch(allProducts);
_.debounce(e => {
console.log('Debounced search:', e);
setResults(results);
}, 1000);
//setResults(results);
}
<TextInput onChangeText={value => handleSearchChange(value)} value={search} style={{ width:'90%', height:'100%', borderRadius:5, padding:10, color:'rgb(68,68,68)',fontSize:16, backgroundColor:'rgba(255,255,255,1)', alignItems:'center' }} placeholder="Donde vamos hoy?"></TextInput>
Please or to participate in this conversation.