Skip to content

Conversation

@genesisquinn
Copy link

No description provided.

};

const likedMessagesCount = messages.reduce(
(count, message) => (message.liked ? count + 1 : count),

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) => {

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,
        }
      }
    });
  });
};

Comment on lines +4 to +5
import TimeStamp from './components/TimeStamp';
import ChatEntry from './components/ChatEntry';

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.

Copy link

@marciaga marciaga left a 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,

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,

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants