diff --git a/src/components/SearchList.jsx b/src/components/SearchList.jsx new file mode 100644 index 0000000..d241463 --- /dev/null +++ b/src/components/SearchList.jsx @@ -0,0 +1,40 @@ +import { useState } from 'react'; + +const SearchList = ({ data, setNewList }) => { + const [value, setValue] = useState(''); + + const handleFiltering = (e) => { + const userInput = e.target.value.toLowerCase(); + setValue(e.target.value); + const gatherItem = []; + for (let i = 0; i < data.length; i++) { + if (data[i]?.name.toLowerCase().includes(userInput)) { + gatherItem.push(data[i]); + } + } + setNewList(gatherItem); + }; + + const resetInput = (e) => { + e.preventDefault(); + setValue(''); + setNewList(data); + }; + + return ( +
+ ); +}; + +export default SearchList; diff --git a/src/views/List.jsx b/src/views/List.jsx index 4b341e3..a354420 100644 --- a/src/views/List.jsx +++ b/src/views/List.jsx @@ -1,13 +1,24 @@ +import { useState, useEffect } from 'react'; import { ListItem } from '../components'; +import SearchList from '../components/SearchList'; +import { useParams } from 'react-router-dom'; export function List({ data }) { + const [newList, setNewList] = useState([]); + const { path } = useParams(); + + useEffect(() => { + setNewList(data); + }, [data]); + return ( <> -
- Hello from the /list
page!
-
{path}
list!
+