Open onmyway133 opened 1 year ago
Use debounce from lodash and useCallback to memoize debounce function
lodash
import React, { useCallback } from "react" import debounce from "lodash/debounce" const SearchField = (props: Props) => { const callback = useCallback( debounce((value: string) => { props.setFilter({ ...props.filter, searchText: value, }) }), [] ) const handleChange = (value: string) => { callback(value) } return ( <div> <Input value={props.filter.searchText} placeholder="Search" variant="bordered" onValueChange={handleChange} /> </div> ) }
Use debounce from
lodash
and useCallback to memoize debounce function