search

mail@pastecode.io avatar
unknown
plain_text
a month ago
729 B
2
Indexable
Never
  const [filteredData, setFilteredData] = useState([]);
  const [searchQuery, setSearchQuery] = useState(''); 
 const handleSearch = () => {
    const filtered = books.filter(book => {
      return (
        book.title.toLowerCase().includes(searchQuery.toLowerCase()) ||
        book.author.toLowerCase().includes(searchQuery.toLowerCase())
      );
    });
    setFilteredData(filtered);
  };

  // nhập dữ liệu vào khung search
  useEffect(() => {
    handleSearch();
  }, [searchQuery]);

 <input
            type="text"
            placeholder="Search..."
            value={searchQuery}
            onChange={(e) => setSearchQuery(e.target.value)}
          />

 {filteredData.map((book) => (
Leave a Comment