Skip to content
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

Muniba K-Zoisite #97

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Muniba K-Zoisite #97

wants to merge 8 commits into from

Conversation

bashmu33
Copy link

No description provided.

Copy link

@kelsey-steven-ada kelsey-steven-ada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on your first solo React project! I've left some questions & comments below, I'd like to highlight the feedback in ChatEntry.js for review. Please take a look when you have the time and reach out here or on Slack if there's anything I can clarify.

src/App.js Outdated
Comment on lines 14 to 22
const addHearts = () => {
let hearts = 0;

for (let i = 0; i < totalLikes; i++) {
hearts += 1
}

return hearts + ' ❤️s';
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since totalLikes is an integer, we could remove this function and use totalLikes + ' ❤️s' anywhere we're calling addHearts.


const ChatEntry = (props) => {
const [likes, setLikes] = useState(props.likes)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current set-up, our data is spread across the project - we don't have a single source of truth that is driving all of the UI. Because of this, when we like a message in ChatEntry, we need to manually keep the like here in ChatEntry in sync with the overall like count in App.js since they both need to display information about the likes.

The best practice is to lift up the state to the App.js level. In that case we would have a piece of useState that represents our chat data in App.js. We could write a function in App.js that we pass down to the ChatEntry component that takes in a message id and uses it to find and update the liked value of the message when a user clicks a heart. If the message state lives in App, then we also have the ability to loop over the messages and count up how many messages have a liked value of true to derive our heart count directly from the data, removing some duplication of data.

sender: PropTypes.string.isRequired,
body: PropTypes.string.isRequired,
timeStamp: PropTypes.string.isRequired,
// likes: PropTypes.bool.isRequired,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder that we want to clean up commented code before opening PRs so it doesn't make it into the final codebase.


ChatLog.propTypes = {
entries: PropTypes.arrayOf(
PropTypes.shape({

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of PropTypes.shape for more detail on what data is expected for this component!

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