Skip to content

Instantly share code, notes, and snippets.

@sbalay
Last active December 14, 2023 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbalay/39fc70f73239931db2bce4781c653e55 to your computer and use it in GitHub Desktop.
Save sbalay/39fc70f73239931db2bce4781c653e55 to your computer and use it in GitHub Desktop.
React Native form, meant to be used with redux-form HOC
import React from 'react';
import { reduxForm, Field } from 'redux-form';
import { ScrollView, Text, TouchableOpacity } from 'react-native';
import MyTextInput from './MyTextInput'
function MyForm(props) {
const formStates = ['asyncValidating', 'dirty', 'pristine', 'valid', 'invalid', 'submitting',
'submitSucceeded', 'submitFailed'];
return (
<ScrollView keyboardShouldPersistTaps={'handled'}>
<Text>Email</Text>
<Field
name={'email'}
component={MyTextInput}
/>
<Text>The form is:</Text>
{
formStates.filter((state) => props[state]).map((state) => {
return <Text key={state}> - { state }</Text>
})
}
<TouchableOpacity onPress={props.handleSubmit}>
<Text>Submit!</Text>
</TouchableOpacity>
</ScrollView>
);
}
export default reduxForm({ form: 'signIn' })(MyForm);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment