-
Notifications
You must be signed in to change notification settings - Fork 117
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
Chatlog G Quinn--Kunzite #112
base: main
Are you sure you want to change the base?
Conversation
}; | ||
|
||
const likedMessagesCount = messages.reduce( | ||
(count, message) => (message.liked ? count + 1 : count), |
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 👍🏽
const [messages, setMessages] = useState(chatMessages); | ||
|
||
const handleLike = (id) => { | ||
const updatedMessages = messages.map((message) => { |
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 works great in this case though I'd recommend using a callback with the update function because it will give you access to the most current previous state, which will ensure you're updating the correct value(s). To use that approach, pass a callback to the update function instead of a value. React will invoke that callback with an argument that represents the most recent state. Then you can use that in whatever computation you need and return the new value you want to set. e.g.
const handleLike = (id) => {
setMessages((previousMessages) => {
return previousMessages.map((message) => {
if (message.id === id) {
return {
...message,
liked: !message.liked,
}
}
});
});
};
import TimeStamp from './components/TimeStamp'; | ||
import ChatEntry from './components/ChatEntry'; |
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.
Neither of these components need to be imported. You should only import components you're directly using. While Chatlog
uses ChatEntry
and ChatEntry
uses TimeStamp
, they only need to be imported in the files in which the actual component is being used.
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.
Good job with this project! Overall well done! Specific comments below, but I'd just add a note that most JavaScript projects will use 2 spaces and I'm seeing mixes 2 and 4 spaces in different files. It's important to be consistent there. Also, it's a good idea to ensure your punctuation syntax follows conventions (i.e. aligning curly braces and parentheses, spacing around punctuation and variables, etc).
//Fill with correct proptypes | ||
sender: PropTypes.string.isRequired, | ||
body: PropTypes.string.isRequired, | ||
timestamp: PropTypes.element.isRequired, |
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.
A couple things to note about timestamp
. First, you're passing a prop to this component called timeStamp
, but this definition is for timestamp
, these are different names. Second, PropTypes.element
means that the type of value is a React element; however, if you meant for this to be timeStamp
, then I think you're passing that prop as a string, so the type should be updated accordingly.
PropTypes.shape({ | ||
sender: PropTypes.string.isRequired, | ||
body: PropTypes.string.isRequired, | ||
TimeStamp: PropTypes.string.isRequired, |
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're getting a warning in the developer tools console for this, TimeStamp
isn't defined. I believe the prop you're passing is called timeStamp
.
No description provided.