Spaces:
Paused
Paused
Download client/src/hooks/useContactList.jsx from arabdullah/chatty: direct link, hf CLI and curl.
- Browser
- Download file 804 Bytes
-
https://huggingface.co/spaces/arabdullah/chatty/resolve/main/client/src/hooks/useContactList.jsx
- Command line
-
hf download hf://spaces/arabdullah/chatty/client/src/hooks/useContactList.jsx
-
curl -L -o useContactList.jsx https://huggingface.co/spaces/arabdullah/chatty/resolve/main/client/src/hooks/useContactList.jsx
804 Bytes
| import { useState, useEffect } from "react"; | |
| import { useSelector } from "react-redux"; | |
| const useContactList = () => { | |
| const contacts = useSelector((state) => state.contactsReducer); | |
| const [searchedContacts, setSearchedContacts] = useState([]); | |
| const [searchValue, setSearchValue] = useState(""); | |
| const handleSearchValue = (event) => { | |
| setSearchValue(event.target.value); | |
| }; | |
| useEffect(() => { | |
| if (searchValue) { | |
| setSearchedContacts( | |
| contacts.filter((contact) => | |
| contact.name.toLowerCase().startsWith(searchValue.toLowerCase()) | |
| ) | |
| ); | |
| } else { | |
| setSearchedContacts(contacts); | |
| } | |
| }, [searchValue, contacts]); | |
| return { | |
| contacts: searchedContacts, | |
| handleSearchValue, | |
| searchValue, | |
| }; | |
| }; | |
| export default useContactList; | |