-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
san chatlog #102
base: main
Are you sure you want to change the base?
san chatlog #102
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job San! Left a few comments. Let me know if you have questions.
import chatMessages from './data/messages.json'; | ||
|
||
const App = () => { | ||
const [chatMessagesData, setChatData] = useState(chatMessages); | ||
|
||
const updateChatData = (updatedMessage) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good!
}; | ||
|
||
|
||
const countLikes = (messages) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great way to use existing data. You could also use the reduce function
return messageData.reduce((totalLikes, message) => {
// If messages.liked is true add 1 to totalLikes, else add 0
return (totalLikes += message.liked ? 1 : 0);
}, 0); // The 0 here sets the initial value of totalLikes to 0
<header> | ||
<h1>Application title</h1> | ||
<h1>A tale of two cities</h1> | ||
<section><span id="heartWidget" className="widget"> {likes} 💚s</span></section> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just call your function in jsx like {countLikes(chatMessageData}
and in Learn you were getting an error message because of the style of heart you are using. You can alter the tests to accept the heart you want to use.
props.onUpdate(updatedMessage); | ||
} | ||
|
||
const likeButton = props.liked ? '💚' : '🤍'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice use of ternary operator here. Your test are currently looking for ❤️. If you don't want to use that update your tests to reflect that.
|
||
ChatLog.propTypes = { | ||
entries: PropTypes.arrayOf( | ||
PropTypes.shape({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great way to specific about what the objects content should be.
No description provided.