Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/components/ChatLog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import PropTypes from 'prop-types';
import ChatEntry from './ChatEntry';
import './ChatLog.css';

const ChatLog = ({ chats }) => {
const getChatLogJSX = (chats) => {
return chats.map((chat) => {
return (
<ChatEntry
key={chat.id}
id={chat.id}
sender={chat.sender}
body={chat.body}
timeStamp={chat.timeStamp}
liked={chat.liked}
/>
);
});
};
return <ul className="chat-log">{getChatLogJSX(chats)}</ul>;
};

ChatLog.propTypes = {
chats: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.number.isRequired,

Choose a reason for hiding this comment

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

nice use of PropTypes to enforce data requirements

sender: PropTypes.string.isRequired,
body: PropTypes.string.isRequired,
timeStamp: PropTypes.string.isRequired,
liked: PropTypes.bool.isRequired,
})
).isRequired,
};

export default ChatLog;