Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@deadcoder0904
Created January 12, 2019 06:17
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 deadcoder0904/c649142dabe1d4a91a98bac1c5d3c437 to your computer and use it in GitHub Desktop.
Save deadcoder0904/c649142dabe1d4a91a98bac1c5d3c437 to your computer and use it in GitHub Desktop.
React Native Simple Form
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