Skip to content

Instantly share code, notes, and snippets.

@sbalay
Last active January 26, 2017 20:11
Show Gist options
  • Save sbalay/27970ec258696e04b084c1d32d4529fc to your computer and use it in GitHub Desktop.
Save sbalay/27970ec258696e04b084c1d32d4529fc to your computer and use it in GitHub Desktop.
React Native's TextInput wrapper to be used with redux-form Field component
import React from 'react';
import { TextInput, View, Text } from 'react-native';
/**
* to be wrapped with redux-form Field component
*/
export default function MyTextInput(props) {
const { input, meta, ...inputProps } = props;
const formStates = ['active', 'autofilled', 'asyncValidating', 'dirty', 'invalid', 'pristine',
'submitting', 'touched', 'valid', 'visited'];
return (
<View>
<TextInput
{...inputProps}
onChangeText={input.onChange}
onBlur={input.onBlur}
onFocus={input.onFocus}
value={input.value}
/>
<Text>The { input.name} input is:</Text>
{
formStates.filter((state) => meta[state]).map((state) => {
return <Text key={state}> - { state }</Text>;
})
}
</View>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment