Skip to content

Instantly share code, notes, and snippets.

@GunaShekar02
Created May 29, 2020 22:35
Show Gist options
  • Save GunaShekar02/e95a9eadf452e5e7b3f59f8ad1d7786a to your computer and use it in GitHub Desktop.
Save GunaShekar02/e95a9eadf452e5e7b3f59f8ad1d7786a to your computer and use it in GitHub Desktop.
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