Created
March 12, 2018 10:36
-
-
Save asmyk/980b9bc7b69fbfe6c31da364175fe1cf to your computer and use it in GitHub Desktop.
Example of standard react-native form component with state
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
import React, { Component } from 'react'; | |
import { StyleSheet, Text, TextInput, View, Button } from 'react-native'; | |
class MyForm extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
name: "", | |
email: "" | |
} | |
this.handleSendClick = this.handleSendClick.bind(this); | |
} | |
handleSendClick() { | |
// necessary validation | |
// everything is valid - send form data up | |
this.props.handleSubmit(this.state); | |
} | |
render() { | |
return ( | |
<View> | |
<TextInput | |
onChangeText={(name) => this.setState({ name })} | |
value={this.state.name} | |
/> | |
<TextInput | |
onChangeText={(email) => this.setState({ email })} | |
value={this.state.email} | |
/> | |
<Button onPress={this.handleSendClick} title="Send" /> | |
</View> | |
) | |
} | |
} | |
export default MyForm; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment