UNPKG

simple-chat-websocket-reactjs

Version:

### Props: In this article we will create a simple chat using websocket, nodeJs and ReactJs. From there you can play around and explore and add your own ideas and features.

35 lines (31 loc) 746 B
import React, { Component } from 'react' import PropTypes from 'prop-types' class ChatInput extends Component { static propTypes = { onSubmitMessage: PropTypes.func.isRequired, } state = { message: '', } render() { return ( <form action="." onSubmit={e => { e.preventDefault() this.props.onSubmitMessage(this.state.message) this.setState({ message: '' }) }} > <input type="text" placeholder={'Enter message...'} value={this.state.message} onChange={e => this.setState({ message: e.target.value })} /> <input type="submit" value={'Send'} /> </form> ) } } export default ChatInput