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

Panthers Tiffany Rogers react-chatlog #125

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

Conversation

Tiffany-Rogers-Dev
Copy link

finished project and show and tell


const toggleLike = (id) => {

setEntries(prevEntries => {

Choose a reason for hiding this comment

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

I know that we did together in my office hours, but please reach out if you need any further explanations as to how and why we want to do this. Great job on following the implementation!

The (Usual) Steps to Lifting Up State:

  1. Establish state with data (from data folder or API) in necessary parent component.
  2. Design updateFunction that uses the id of an object to preforms desired changes and updates state.
  3. Pass updateFunction to necessary children components
  4. Make updateFunction the event handler and passing prop.id as parameter.

ChatEntry.propTypes = {
//Fill with correct proptypes

Choose a reason for hiding this comment

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

Don'r forget you also want to include the toggleLike function you are passing in as a prop as well!

@@ -1,22 +1,28 @@
import React from 'react';
import './ChatEntry.css';
import PropTypes from 'prop-types';
import TimeStamp from './TimeStamp';

const ChatEntry = (props) => {

Choose a reason for hiding this comment

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

Just a friendly reminder that we can also de-structure our props with const ChatEntry = ( {myProp}) to have direct access to them!


return (

<ChatEntry

Choose a reason for hiding this comment

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

So you see how setting all of those props took up a lot of lines of code? We could make that more concise with this here:

 < ChatEntry toggleLike={props.toggleLike} key={entry.id} entry={entry} />

Then in each chatEntry we could access any prop we needed with props.entry.myProp

};
</>
)};

Choose a reason for hiding this comment

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

Remember to put your props-types checking for this one. You could use the arrayOf and then shape functionality to be very explicit about the data structure you are expecting to pass through here.


const ChatEntry = (props) => {
return (
return(
<div className="chat-entry local">

Choose a reason for hiding this comment

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

I see you didn't do the optional enhancement, just in case you were wondering about how it worked you could basically use the ids of each message to decide if it should be on the right or left side of the screen. the receiver would always be an even id and the sender would always be odd.

const localRemote = props.id % 2 === 0 ? 'chat-entry local' : 'chat-entry remote';

then we could assign could put this class name in the div on line 8

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