A simple React application that demonstrates filtering a list of items based on user input
- Using
useStateto manage component state - Using
useEffectto respond to state changes - Passing props between components
- Filtering arrays based on search terms
- Creating reusable components
src/
├── App.jsx # Main app component
├── data/
│ └── people.json # Sample data for the list
├── components/
│ ├── FilteredList.jsx # Main filtering component
│ ├── SearchBar.jsx # Search input component
│ └── ItemList.jsx # Display filtered results
└── CSS files for each component
- React 18 - UI library
- Vite - Build tool and development server
- CSS3 - Styling with modern features
- JavaScript ES6+ - Modern JavaScript features
The data is stored in src/data/people.json with an array of 10 people containing:
- id, name, email, category
- 1 Boss, 1 Leader, 6 Developers, 1 Designer, 1 Tester
The App.jsx component imports this JSON data and passes it to the FilteredList component.
The FilteredList component manages:
searchTerm- what the user typesselectedCategory- which category filter is selectedfilteredItems- the results after filteringcategories- list of unique categories
When searchTerm or selectedCategory changes, useEffect runs and:
- Starts with all items
- Filters by search term (checks name and email)
- Filters by category (if not "All")
- Updates
filteredItemsstate
The filtered items are passed to ItemList which renders them as cards.