P
P
p4p2019-08-25 17:01:55
React Native
p4p, 2019-08-25 17:01:55

How to understand the React Native application code, what is going on here?

handleChange = key => val =>
  {
    this.setState({ [key]: val })
  }

<TextInput
          placeholder="Логин"
          style={styles.input}
          value = {this.state.login}
          onChangeText = {this.handleChange('login')}
        />

Here handleChange is what in general? Why is {this.handleChange('login')} being used as a method here?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
NiyazNA, 2019-08-25
@NiyazNA

You must pass an event handler function to onChangeText.
onChangeText = {this.handleChange('login')}Here comes the function call handleChange, which will return a function, which in turn will change the state of the application, receiving keyfrom the closure (in your example, key = "login"), but valI don’t know where it will be received from. Maybe it's some kind of React Native feature.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question