Created
May 29, 2020 22:35
-
-
Save GunaShekar02/e95a9eadf452e5e7b3f59f8ad1d7786a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { useRecoilState, useRecoilValue } from "recoil"; | |
import styles from "./ContactList.module.css"; | |
import { currentContactState } from "../../recoil/atoms"; | |
import { contactsList } from "../../recoil/selectors"; | |
const ContactList = () => { | |
const [currentContact, setCurrentContact] = useRecoilState(currentContactState); | |
const contacts = useRecoilValue(contactsList); | |
return contacts.map((contact) => ( | |
<div | |
key={contact.id} | |
className={`${styles.name_container} ${ | |
currentContact === contact.id ? styles.name_selected : null | |
}`} | |
onClick={() => setCurrentContact(contact.id)} | |
> | |
{contact.name} | |
</div> | |
)); | |
}; | |
export default ContactList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment