Last active
May 1, 2022 20:15
-
-
Save pushkar100/a9af291de92192507dab80ac7ec312d3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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, { useState, useCallback } from "react"; | |
| const readStyle = { backgroundColor: "grey" }; | |
| const unreadStyle = { backgroundColor: "white" }; | |
| const EmailsListItem = ({ hasRead, onReadStatusChange }) => { | |
| const [read, setRead] = useState(hasRead || false); | |
| const resetRead = useCallback(() => { | |
| setRead(hasRead); | |
| // Handle side effects during a reset! | |
| if (onReadStatusChange) { | |
| onReadStatusChange(hasRead); | |
| } | |
| }, [hasRead]); | |
| const style = read ? readStyle : unreadStyle; | |
| return ( | |
| <div style={style}> | |
| <div>Subject: Email one, Content: Hello</div> | |
| <button | |
| onClick={() => { | |
| /* Renders email content */ | |
| setRead(true); | |
| }} | |
| > | |
| Open | |
| </button> | |
| <button onClick={() => resetRead()}>Reset read</button> | |
| </div> | |
| ); | |
| }; | |
| export default EmailsListItem; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment