Created
December 5, 2025 11:56
-
-
Save nodomw/f2e808dbe93697e3fa5d40b717edf014 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useState } from "react"; | |
| type SearchResult = { | |
| index: number; | |
| content: string; | |
| }; | |
| const data: SearchResult[] = [ | |
| { index: 1, content: "apple" }, | |
| { index: 2, content: "banana" }, | |
| { index: 3, content: "cherry" }, | |
| { index: 4, content: "date" }, | |
| { index: 5, content: "elderberry" }, | |
| ]; | |
| function Search() { | |
| const [query, setQuery] = useState(""); | |
| const result = data.filter((item) => | |
| item.content | |
| .toLowerCase() | |
| .includes(query.toLowerCase()), | |
| ); | |
| return ( | |
| <div> | |
| <input | |
| onChange={(e) => setQuery(e.target.value)} | |
| type="text" | |
| placeholder="Search..." | |
| /> | |
| <ul> | |
| {result.map((res) => ( | |
| <li key={res.index}>{res.content}</li> | |
| ))} | |
| </ul> | |
| </div> | |
| ); | |
| } | |
| export default Search; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment