Skip to content
Justice Tech School

Project: Live Search

Filter a list as the user types.

Example
function Search({ items }) {
  const [q, setQ] = useState("");
  const shown = items.filter((i) => i.toLowerCase().includes(q.toLowerCase()));
  return (
    <>
      <input value={q} onChange={(e) => setQ(e.target.value)} />
      <ul>{shown.map((i) => <li key={i}>{i}</li>)}</ul>
    </>
  );
}

Exercise

Case insensitive.

i.().includes(q)

Quiz Test

Is shown stored in state?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.