Skip to content

Instantly share code, notes, and snippets.

@pushkar100
Last active May 1, 2022 20:01
Show Gist options
  • Select an option

  • Save pushkar100/dd1616754c7bf3d01fd86c8d159dac71 to your computer and use it in GitHub Desktop.

Select an option

Save pushkar100/dd1616754c7bf3d01fd86c8d159dac71 to your computer and use it in GitHub Desktop.
import React, { useState, useCallback } from "react";
const readStyle = { backgroundColor: "grey" };
const unreadStyle = { backgroundColor: "white" };
const EmailsListItem = ({ hasRead }) => {
const [read, setRead] = useState(hasRead || false);
const resetRead = useCallback(() => setRead(hasRead), [hasRead]);
const style = read ? readStyle : unreadStyle;
return (
<div style={style}>
<div>Subject: Email one, Content: Hello</div>
<button
onClick={() => {
/* Renders email content */
}}
>
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