Skip to content

Commit 4b3a8f1

Browse files
committed
Update ContactList.jsx
1 parent b6216ee commit 4b3a8f1

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/components/contactList/ContactList.jsx

+12-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,25 @@ import PropTypes from 'prop-types';
33
import styles from './ContactList.module.css';
44
import ContactItem from '../contactItem/ContactItem';
55

6-
const ContactList = ({ contacts, onDeleteContact }) => {
6+
import { useDispatch, useSelector } from 'react-redux';
7+
import { deleteContact } from 'redux/slices/contactsSlice';
8+
9+
const ContactList = () => {
10+
const dispatch = useDispatch();
11+
const contacts = useSelector(state => state.contacts);
12+
13+
const handleDeleteContact = contactId => {
14+
dispatch(deleteContact(contactId));
15+
};
16+
717
return (
818
<div className={styles.container}>
919
<ul className={styles.label}>
1020
{contacts.map(contact => (
1121
<ContactItem
1222
key={contact.id}
1323
contact={contact}
14-
onDeleteContact={onDeleteContact}
24+
onDeleteContact={handleDeleteContact}
1525
/>
1626
))}
1727
</ul>
@@ -27,7 +37,6 @@ ContactList.propTypes = {
2737
number: PropTypes.string.isRequired,
2838
})
2939
).isRequired,
30-
onDeleteContact: PropTypes.func.isRequired,
3140
};
3241

3342
export default ContactList;

0 commit comments

Comments
 (0)