Skip to content

Instantly share code, notes, and snippets.

@asmyk
Created March 12, 2018 11:31
Show Gist options
  • Save asmyk/6bf552d4e1c326391664048d20bd8c14 to your computer and use it in GitHub Desktop.
Save asmyk/6bf552d4e1c326391664048d20bd8c14 to your computer and use it in GitHub Desktop.
React native form example with recompose
class MyForm extends Component {
render() {
let { formData, onSubmitForm } = this.props;
return (
<View>
<TextInput value={formData.name} />
<TextInput value={formData.email} />
<Button onPress={onSubmitForm} title="Send" />
</View>
)
}
}
let initialState = {
name: 'Eric',
email: '[email protected]'
}
let enhance = compose(
withState('formData', 'setFormData', initialState),
withHandlers({ onSubmitForm: (props) => event => { console.log('form submitted!') } })
)
export default enhance(MyForm);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment