Skip to content

Instantly share code, notes, and snippets.

@PCreations
Created August 27, 2017 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save PCreations/db4716049c1332e72b7bd32d30843f5b to your computer and use it in GitHub Desktop.
Save PCreations/db4716049c1332e72b7bd32d30843f5b to your computer and use it in GitHub Desktop.
Simple message input
import React from 'react';
import PropTypes from 'prop-types';
import withState from 'recompose/withState';
import withHandlers from 'recompose/withHandlers';
import compose from 'recompose/compose';
const enhance = compose(
withState('value', 'updateValue', ''),
withHandlers({
onChange: props => event => {
props.updateValue(event.target.value);
},
onSubmit: props => event => {
event.preventDefault();
props.updateValue('');
props.sendMessage(props.value);
},
})
);
const MessageInput = enhance(({ value, onChange, onSubmit }) =>
<form onSubmit={onSubmit}>
<label>Value
<input type="text" value={value} onChange={onChange} />
<input type="submit"/>
</label>
</form>
)
MessageInput.propTypes = {
sendMessage: PropTypes.func.isRequired,
};
export default MessageInput;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment