Sometimes you need the input to filter a list by specific properties, in that case you can provide items option and filterByColumns and then to use filteredItems.
Remember to useMemo in case the creation of the array is inside the component that use the hook
use this options can reduce Ajax/renders when the user typing and try to filter a list
import*asReactfrom'react'
importuseDebounceInputfrom'use-debounce-input'
constWithArray=()=>{
constitems=useMemo(()=>[
{id:'111-111',name:'Ben'},
{id:'111-222',name:'Guy'},
{id:'111-333',name:'Helit'},
],[])
const{
DebounceInput,
value,
debounceValue,
filteredItems
}=useDebounceInput({
delay:400,
items,
filterByColumns:['id']
});
return(
<div>
<DebounceInput/>
<br/>
Value: {value}
<br/>
DebounceValue: {debounceValue}
<br/>
<table>
{filteredItems.map(filteredItem=>(
<tr>
<td>{filteredItem.id}</td>
<td>{filteredItem.name}</td>
</tr>
))}
</table>
</div>
)
}
Custom Filter
For custom filtering you can use filter option. The function will get (debounceValue, items, filterByColumns) params and should return newArray of filtered items. the function can be async function