How to create a search textbox filter in React?
Build a live search filter using useState and array filter() to display matching results in real time.
intermediateForms and inputsreactfiltersearchuseState
Published: 10/26/2025
Updated: 10/26/2025
Question
How to create a search textbox filter in React?
Answer
Use useState to capture input and filter() to show matching items.
import { useState } from 'react';
function SearchFilter() {
const [query, setQuery] = useState('');
const items = ['React', 'Vue', 'Angular', 'Svelte'];
const filtered = items.filter((item) =>
item.toLowerCase().includes(query.toLowerCase())
);
return (
<div>
<input
placeholder='Search...'
value={query}
onChange={(e) => setQuery(e.target.value)}
/>
<ul>
{filtered.map((item) => (
<li key={item}>{item}</li>
))}
</ul>
</div>
);
}
Real-World Example
Used in:
- Searchable lists
- Product filters
- User management panels
Quick Practice
Create a searchable “Developer Skills” list with live filtering.
Summary
Use filter() with state to create instant client-side search features.
Related Videos
Watch these videos to learn more about this topic
Frequently Asked Questions
Can I debounce a search input?
Yes. Use setTimeout or a custom hook to delay API calls.
Stay Updated
Get the latest frontend challenges, interview questions and tutorials delivered to your inbox.