Skip to content

Commit 89b500d

Browse files
committed
feat: optimize search functionality with debounced input handling
1 parent 0663391 commit 89b500d

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

apps/web/components/feature/devlog/devlog-list.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import React, { useState } from 'react';
3+
import React, { useState, useCallback, useMemo } from 'react';
44
import { Button } from '@/components/ui/button';
55
import { Input } from '@/components/ui/input';
66
import {
@@ -185,15 +185,22 @@ export function DevlogList({
185185
};
186186

187187
// Handle search
188-
const handleSearch = debounce((value: string) => {
188+
const debouncedFilterChange = useMemo(
189+
() => debounce((value: string) => {
190+
if (onFilterChange) {
191+
onFilterChange({
192+
...filters,
193+
search: value || undefined,
194+
});
195+
}
196+
}, 300),
197+
[onFilterChange, filters]
198+
);
199+
200+
const handleSearch = useCallback((value: string) => {
189201
setSearchText(value);
190-
if (onFilterChange) {
191-
onFilterChange({
192-
...filters,
193-
search: value || undefined,
194-
});
195-
}
196-
});
202+
debouncedFilterChange(value);
203+
}, [debouncedFilterChange]);
197204

198205
// Handle filter changes
199206
const handleFilterChange = (key: string, value: string | undefined) => {

0 commit comments

Comments
 (0)