Created
January 12, 2019 06:17
-
-
Save deadcoder0904/c649142dabe1d4a91a98bac1c5d3c437 to your computer and use it in GitHub Desktop.
React Native Simple Form
This file contains hidden or 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
class Form extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
name: "", | |
email: "", | |
}; | |
} | |
_storeInput = (key, value) => { | |
this.setState({ | |
[key]: value, | |
}); | |
}; | |
_onSubmit = () => { | |
const { name, email } = this.state; | |
if (name !== "" && email !== "") { | |
// implement axios here | |
} | |
}; | |
render() { | |
const { name, email } = this.state; | |
return ( | |
<View> | |
<TextInput | |
onChangeText={() => this._storeInput("name", name)} | |
value={name} | |
/> | |
<TextInput | |
onChangeText={() => this._storeInput("email", email)} | |
value={email} | |
/> | |
<TouchableHighlight onPress={this._onSubmit}> | |
<Text>Submit</Text> | |
</TouchableHighlight> | |
</View> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment