How to submit a form in React Native
On the <input
you need to add something like this, example:
<Input onChangeText={(text) => this.setState({username: text})} value={this.state.username}
And when you use the onPress
function you just need to get the this.state.username and use it when you want.
I don't usually do a function that handle the Login
or something in other .js
so you need to pass the this.state.username
to the page
that handles it.
What i usually do if I really need to pass something to other page
is using GLOBALS
, example:
// globals.js
module.exports = {
username: '',
};
And then to use the globals.js
// import the globals.js
GLOBAL = require('./globals');
<Input onChangeText={(text) => this_onButtonPressed(text) value={this.state.username}/>
_onButtonPressed(text){
GLOBAL.username = this.state.username
// call function that handles it
}
And then on the page
that handles it you need to import
it again and just use GLOBAL.username.
If you didn't understand it tell me I will try to explain it better, I need to know if you want to handle the login
on a different .js
or it can be on the .js
that has the Form (its easier like this)