I have read similar questions here
Why shouldn't JSX props use arrow functions or bind?
JSX props should not use .bind() - how to avoid using bind?
No .bind() or Arrow Functions in JSX Props making no sense to me when I need to pass arguments
And I understand how using an arrow function causes the function to be recreated on each render and effects performance. However I still don't fully understand how to resolve this issue in React Native, specifically when using setState.
For example, if I have a TextInput that updates a value held in the component state in the onChangeText function, how do I avoid using an arrow function?
<TextInput
value={this.state.text}
onChangeText={text => this.setState({ text })}
/>
Must I create a handler for each property in the state that I want to update? For example, if I have two TextInput fields Email and Password, would that need to be handled like this?
updateEmail = email => {
this.setState({ email })
}
updatePassword = password => {
this.setState({ password })
}
render() {
...
<TextInput
value={this.state.email}
onChangeText={this.updateEmail}
/>
<TextInput
value={this.state.password}
onChangeText={this.updatePassword}
/>