Skip to content

Instantly share code, notes, and snippets.

@nodomw
Created December 5, 2025 11:56
Show Gist options
  • Select an option

  • Save nodomw/f2e808dbe93697e3fa5d40b717edf014 to your computer and use it in GitHub Desktop.

Select an option

Save nodomw/f2e808dbe93697e3fa5d40b717edf014 to your computer and use it in GitHub Desktop.
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