diff --git a/src/components/Chat/index.js b/src/components/Chat/index.js new file mode 100644 index 0000000..51c22ee --- /dev/null +++ b/src/components/Chat/index.js @@ -0,0 +1,54 @@ +import React from "react"; +import "./Chat.css"; +import Message from "./../Message"; + +class Chat extends React.Component { + + state = { + messageInput: "", + messages: [] + }; + + changeInputMessage = (e) => { + this.setState({ + messageInput: e.target.value + }); + }; + + sendMessageOnEnter = (e) => { + if (e.key === "Enter") { + this.setState((prevState) => { + return { + messageInput: "", + messages: prevState.messages.concat([{ text: prevState.messageInput }]) + }; + }); + } + }; + + render() { + + const messagesArr = this.state.messages; + const messageInput = this.state.messageInput; + + return ( +