mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 14:38:45 +00:00
tweak(phone/contacts): Tweak contact actions to remove unneeded dep
This commit is contained in:
1 parent
5493a3de76
commit
28fd09ce53
1 file changed
+13
-11
@@ -54,28 +54,30 @@ export const useContactActions = (): UseContactsValue => {
|
||||
|
||||
const deleteContact = useCallback(
|
||||
(id: number): void => {
|
||||
const newContacts = [...contacts].filter((contact) => contact.id !== id);
|
||||
setContacts(newContacts);
|
||||
setContacts((curContacts) => [...curContacts].filter((contact) => contact.id !== id));
|
||||
},
|
||||
[contacts, setContacts],
|
||||
[setContacts],
|
||||
);
|
||||
|
||||
const addContact = useCallback(
|
||||
(contact: Contact) => {
|
||||
const newContactState = [...contacts, contact];
|
||||
setContacts(newContactState);
|
||||
setContacts((curContacts) => [...curContacts, contact]);
|
||||
},
|
||||
[contacts, setContacts],
|
||||
[setContacts],
|
||||
);
|
||||
|
||||
const updateContact = useCallback(
|
||||
(updatedContact: Contact) => {
|
||||
const targetContactIndex = contacts.findIndex((contact) => contact.id === updatedContact.id);
|
||||
const newContactsArray = [...contacts];
|
||||
newContactsArray[targetContactIndex] = updatedContact;
|
||||
setContacts(newContactsArray);
|
||||
setContacts((curContacts) => {
|
||||
const targetContactIndex = curContacts.findIndex(
|
||||
(contact) => contact.id === updatedContact.id,
|
||||
);
|
||||
const newContactsArray = [...curContacts];
|
||||
newContactsArray[targetContactIndex] = updatedContact;
|
||||
return newContactsArray;
|
||||
});
|
||||
},
|
||||
[contacts, setContacts],
|
||||
[setContacts],
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user