Skip to content

Commit

Permalink
merged useEffects and changed clear button
Browse files Browse the repository at this point in the history
  • Loading branch information
sar-mko committed Aug 31, 2024
1 parent b8dc409 commit 09f2d77
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/views/List.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ export function List({ data }) {
setFilterVal('');
};

useEffect(() => {
setFilteredList(data);
}, [data]);

useEffect(() => {
setFilteredList(
data.filter((item) =>
item.name.toLowerCase().includes(filterVal.toLowerCase()),
),
);
}, [filterVal]);
}, [filterVal, data]);

return (
<>
Expand All @@ -37,7 +33,7 @@ export function List({ data }) {
value={filterVal}
onChange={(e) => setFilterVal(e.target.value)}
/>
<button>Clear</button>
{filterVal && <button>Clear</button>}
</form>

<ul>
Expand Down

0 comments on commit 09f2d77

Please sign in to comment.