import { Search, X } from "lucide-react"; import { useState, useEffect, type ComponentProps } from "react"; import { Button } from "./ui/button"; import { Input } from "./ui/input"; import { cn } from "~/lib/utils"; export default function InputSearch(props: ComponentProps<"input">) { const [value, setValue] = useState(String(props.value ?? "")); // Đồng bộ khi value từ props thay đổi useEffect(() => { setValue(String(props.value ?? "")); }, [props.value]); const handleChange = (newValue: string) => { setValue(newValue); props.onChange?.({ ...({} as any), // Type trick target: { value: newValue }, } as React.ChangeEvent); }; return (
handleChange(e.target.value)} value={value} /> {value.length > 0 && ( )}
); }