Created
August 27, 2017 15:31
-
-
Save PCreations/db4716049c1332e72b7bd32d30843f5b to your computer and use it in GitHub Desktop.
Simple message input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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