tweak(phone/contacts): Tweak contact actions to remove unneeded dep

This commit is contained in:
Taso committed 2021-06-08 16:45:57 -04:00
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 {