-
Notifications
You must be signed in to change notification settings - Fork 45
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
C22 - Sphinx -Tatiana Trofimova #40
base: main
Are you sure you want to change the base?
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.
Nice job on react-chatlog!
const App = () => { | ||
const [messagesData, setMessagesData] = useState(messages); | ||
const [likesCounter, setLikesCounter] = useState(0); |
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.
We can calculate the number of likes from messagesData
. Therefore we should remove the likesCounter
state. When possible, we should prefer to not use state if we can calculate whatever value instead so that we don't introduce additional, unnecessary complexity.
} | ||
}); | ||
}); | ||
setLikesCounter( (likesCounter) => likesCounter + likeAdjustment); |
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.
Instead of using state for likesCount
, we should remove this state completely.
We can create a helper function that calls reduce
that can get the count of all the likes from messages
, like:
const getLikedCount = () => {
return messages.reduce((totalLikes, message) => (totalLikes + message.liked), 0);
};
return ( | ||
<div id="App"> | ||
<header> | ||
<h1>Application title</h1> | ||
<h1>Chat between {participants.join(' and ')}</h1> | ||
<h2 className='heartWidget'>Likes: {likesCounter}</h2> |
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.
To have this element look like the provided wireframes, you would write:
<h2 className='heartWidget'>{likesCounter()} ❤️s</h2>
return ( | ||
<div id="App"> | ||
<header> | ||
<h1>Application title</h1> | ||
<h1>Chat between {participants.join(' and ')}</h1> |
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.
While this bit of logic isn't complex and is concise, I still think it would be nice to write a helper function and invoke the helper function here. Maybe something like getChatParticipants
const App = () => { | ||
const [messagesData, setMessagesData] = useState(messages); | ||
const [likesCounter, setLikesCounter] = useState(0); | ||
const [participants, setParticipants] = useState([]); |
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.
Do we need to keep track of participants by using state? Could you render the header on line 49 without it?
We should prefer to not use state when we don't absolutely need it.
<p className="entry-time">Replace with TimeStamp component</p> | ||
<button className="like">🤍</button> | ||
<p>{body}</p> | ||
<p className="entry-time">{TimeStamp(timeStamp)}</p> |
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 job using the provided TimeStamp
component!
return ( | ||
<div className='chat-log'> | ||
{feed} | ||
</div> |
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 job capturing the return value from invoking map
in the variable feed
and using that variable here. This is typical of what you'd see in industry!
No description provided.