Skip to content

Commit

Permalink
Update ContactItem.jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
danretegan committed Feb 25, 2024
1 parent 4b3a8f1 commit 4a4f36a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/components/contactItem/ContactItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@ import PropTypes from 'prop-types';
import styles from './ContactItem.module.css';
import Button from '../Button';

const ContactItem = ({ contact, onDeleteContact }) => {
import { useDispatch } from 'react-redux';
import { deleteContact } from '../../redux/slices/contactsSlice';

const ContactItem = ({ contact }) => {
const dispatch = useDispatch();

const handleDeleteContact = () => {
dispatch(deleteContact(contact.id));
};

return (
<div className={styles.item}>
<li>
<strong>{contact.name}</strong>: <br /> {contact.number}
</li>
<Button action={() => onDeleteContact(contact.id)}>Delete</Button>
<Button action={handleDeleteContact}>Delete</Button>
</div>
);
};
Expand All @@ -20,7 +29,6 @@ ContactItem.propTypes = {
name: PropTypes.string.isRequired,
number: PropTypes.string.isRequired,
}).isRequired,
onDeleteContact: PropTypes.func.isRequired,
};

export default ContactItem;

0 comments on commit 4a4f36a

Please sign in to comment.