Commit 4b3a8f1 1 parent b6216ee commit 4b3a8f1 Copy full SHA for 4b3a8f1
File tree 1 file changed +12
-3
lines changed
src/components/contactList
1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -3,15 +3,25 @@ import PropTypes from 'prop-types';
3
3
import styles from './ContactList.module.css' ;
4
4
import ContactItem from '../contactItem/ContactItem' ;
5
5
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
+
7
17
return (
8
18
< div className = { styles . container } >
9
19
< ul className = { styles . label } >
10
20
{ contacts . map ( contact => (
11
21
< ContactItem
12
22
key = { contact . id }
13
23
contact = { contact }
14
- onDeleteContact = { onDeleteContact }
24
+ onDeleteContact = { handleDeleteContact }
15
25
/>
16
26
) ) }
17
27
</ ul >
@@ -27,7 +37,6 @@ ContactList.propTypes = {
27
37
number : PropTypes . string . isRequired ,
28
38
} )
29
39
) . isRequired ,
30
- onDeleteContact : PropTypes . func . isRequired ,
31
40
} ;
32
41
33
42
export default ContactList ;
You can’t perform that action at this time.
0 commit comments