diff --git a/src/components/atoms/SearchInput/index.tsx b/src/components/atoms/SearchInput/index.tsx new file mode 100644 index 0000000..9d1b996 --- /dev/null +++ b/src/components/atoms/SearchInput/index.tsx @@ -0,0 +1,36 @@ +"use client"; +import { FC, useEffect, useState } from "react"; + +type Props = { + defaultValue?: string; + placeholder?: string; + onChange?: (value: string) => void; + debounce?: number; +}; + +export const SearchInput: FC = ({ + defaultValue = "", + placeholder = "Search", + onChange, + debounce = 500, +}) => { + const [value, setValue] = useState(defaultValue); + + useEffect(() => { + const timer = setTimeout(() => { + onChange?.(value ?? ""); + }, debounce); + + return () => clearTimeout(timer); + }, [value]); + + return ( + setValue(e.target.value)} + /> + ); +};