diff --git a/src/app/(private)/roles/page.tsx b/src/app/(private)/roles/page.tsx index bd4dfdf..dbaf1d4 100644 --- a/src/app/(private)/roles/page.tsx +++ b/src/app/(private)/roles/page.tsx @@ -152,7 +152,7 @@ const Page = (): JSX.Element => { id="name" label={t('name')} value={filters.name} - onChange={(e) => handleFilterChange('name', e.target.value)} + onChange={(value) => handleFilterChange('name', value)} /> ) => void + onChange: (value: string) => void placeholder?: string type?: string } @@ -19,8 +21,18 @@ const FilterInput: React.FC = ({ placeholder = '', type = 'text', }) => { + const [localValue, setLocalValue] = useState(value ?? '') + + // Debounce the onChange callback to minimize frequent calls + const debouncedChange = useMemo( + () => debounce((newValue: string) => onChange(newValue), 300), + [onChange] + ) + const handleChange = (e: React.ChangeEvent) => { - onChange(e) + const newValue = e.target.value + setLocalValue(newValue) // Update the local state immediately for user feedback + debouncedChange(newValue) // Call the debounced onChange function } return ( @@ -28,7 +40,7 @@ const FilterInput: React.FC = ({