Search Filter Component Flashcards

1
Q

What is the basic react framework for SearchFilter?

A
const SearchFilter = () => {
return (
<div>
Search: 
</div>
)}

export default SearchFilter;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Create the handleSearch function part 1

A
  1. Create dummy list array of variables
  2. Import useState from react

const [filterList, setFilterList] = useState(list);

const handleSearch = (event) => {
if (event.target.value === “”) {
setFilterList(list);
return;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

handleSearch function part 2 (filtered values)

A
const filteredValues = list.filter(
(item) => item.toLowerCase().indexOf(event.target.value.toLowerCase() ) ==! -1
);
setFilterList(filterValues);
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Return the filtered list

A
After the <div> in the return statement:
{filterList && 
filterList.map((item, index) => (
<div>{item}</div>
))}
</div>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly