mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +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(
|
const deleteContact = useCallback(
|
||||||
(id: number): void => {
|
(id: number): void => {
|
||||||
const newContacts = [...contacts].filter((contact) => contact.id !== id);
|
setContacts((curContacts) => [...curContacts].filter((contact) => contact.id !== id));
|
||||||
setContacts(newContacts);
|
|
||||||
},
|
},
|
||||||
[contacts, setContacts],
|
[setContacts],
|
||||||
);
|
);
|
||||||
|
|
||||||
const addContact = useCallback(
|
const addContact = useCallback(
|
||||||
(contact: Contact) => {
|
(contact: Contact) => {
|
||||||
const newContactState = [...contacts, contact];
|
setContacts((curContacts) => [...curContacts, contact]);
|
||||||
setContacts(newContactState);
|
|
||||||
},
|
},
|
||||||
[contacts, setContacts],
|
[setContacts],
|
||||||
);
|
);
|
||||||
|
|
||||||
const updateContact = useCallback(
|
const updateContact = useCallback(
|
||||||
(updatedContact: Contact) => {
|
(updatedContact: Contact) => {
|
||||||
const targetContactIndex = contacts.findIndex((contact) => contact.id === updatedContact.id);
|
setContacts((curContacts) => {
|
||||||
const newContactsArray = [...contacts];
|
const targetContactIndex = curContacts.findIndex(
|
||||||
newContactsArray[targetContactIndex] = updatedContact;
|
(contact) => contact.id === updatedContact.id,
|
||||||
setContacts(newContactsArray);
|
);
|
||||||
|
const newContactsArray = [...curContacts];
|
||||||
|
newContactsArray[targetContactIndex] = updatedContact;
|
||||||
|
return newContactsArray;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
[contacts, setContacts],
|
[setContacts],
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in new issue
Block a user