Last active
January 26, 2017 20:11
-
-
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
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 { 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