Scope binding for react app




Class level function binding

If you write you code this way, this -> is class scoped. If you have defined username / password in your state, then you will be able to access it.



<Button onPress={() => {
this.authenticate(this.state.username, this.state.password);
}}
/>



If you tend to write you code this way, it means a local binding function,


<Button onPress={this.authenticate} title="Login" />


async authenticate() {


username = this.state.username; //undefined
password = this.state.password; // undefined
}

Comments

Popular posts from this blog

PySpark - Working with JDBC Sqlite database