title: React Native onChangeText like onChange in ReactJS
body: <p>I learn in the same time ReactJS and React Native. I saw in an udemy tutorial something very beautiful, that the professor putt it just one onChange method, for all inputs and taking advantage of the "name" attribute, he could do this:</p>
  
  <pre><code>const onChange = event =&gt;
      setFormData({ ...formData, [event.target.name]: event.target.value });
  </code></pre>
  
  <p>So he said, instead of having for each onChange, inside of each input, a different method, we can have only one.</p>
  
  <p>This is the code that I'm talking about:</p>
  
  <pre><code>const Register = props =&gt; {
    const [formData, setFormData] = useState({
      name: '',
      email: '',
      password: '',
      password2: ''
    });
  
    const { name, email, password, password2 } = formData;
    const onChange = event =&gt;
      setFormData({ ...formData, [event.target.name]: event.target.value });
  
    const onSubmit = async event =&gt; {
      event.preventDefault();
      if (password !== password2) {
        props.setAlert('Passwords do not match', 'danger', 5000);
      } else {
        props.registerUser({ name, email, password });
      }
    };
  
  
    if (props.isAuthenticated) {
      return &lt;Redirect to="/dashboard" /&gt;;
    }
    return (
      &lt;Fragment&gt;
        &lt;h1 className="large text-primary"&gt;Sign Up&lt;/h1&gt;
        &lt;p className="lead"&gt;
          &lt;i className="fas fa-user" /&gt; Create Your Account
        &lt;/p&gt;
        &lt;form className="form" onSubmit={event =&gt; onSubmit(event)}&gt;
          &lt;div className="form-group"&gt;
            &lt;input
              type="text"
              placeholder="Name"
              name="name"
              value={name}
              onChange={event =&gt; onChange(event)}
            /&gt;
          &lt;/div&gt;
          &lt;div className="form-group"&gt;
            &lt;input
              type="email"
              placeholder="Email Address"
              name="email"
              value={email}
              onChange={event =&gt; onChange(event)}
            /&gt;
            &lt;small className="form-text"&gt;
              This site uses Gravatar so if you want a profile image, use a
              Gravatar email
            &lt;/small&gt;
          &lt;/div&gt;
          &lt;div className="form-group"&gt;
            &lt;input
              type="password"
              placeholder="Password"
              name="password"
              // minLength="6"
              value={password}
              onChange={event =&gt; onChange(event)}
            /&gt;
          &lt;/div&gt;
          &lt;div className="form-group"&gt;
            &lt;input
              type="password"
              placeholder="Confirm Password"
              name="password2"
              value={password2}
              onChange={event =&gt; onChange(event)}
            /&gt;
          &lt;/div&gt;
          &lt;input type="submit" className="btn btn-primary" value="Register" /&gt;
        &lt;/form&gt;
        &lt;p className="my-1"&gt;
          Already have an account? &lt;Link to="/login"&gt;Sign In&lt;/Link&gt;
        &lt;/p&gt;
      &lt;/Fragment&gt;
    );
  };
  </code></pre>
  
  <p>In React Native, that is with a different professor, I tried to think how to do this. I tried a few days the offered props from the TextInput but non of then, in my opinion, can be used how we can use the "name" attribute in ReactJS.</p>
  
  <p>This is the code for the React Native app:</p>
  
  <pre><code>import React, { Component } from 'react';
  import {
    StyleSheet,
    View,
    Button,
    TextInput,
  } from 'react-native';
  
  class PlaceInput extends Component {
    state = {
      userName: '',
      placeName: ''
    }
  
    userNameChangeHandler = (value) =&gt; {
      this.setState({ userName: value })
    }
  
    placeNameChangeHandler = (value) =&gt; {
      this.setState({ placeName: value })
    }
  
    placeSubmitHandler = () =&gt; {
      if (this.state.placeName.trim() === '') {
        return;
      }
  
      this.props.onPlaceAdded(this.state.placeName)
    }
  
    render() {
      return (
        &lt;View style={styles.inputContainer}&gt;
          &lt;TextInput
            style={styles.placeInput}
            value={this.state.userName}
            onChangeText={this.userNameChangeHandler}
            placeholder='User Name' /&gt;
          &lt;TextInput
            style={styles.placeInput}
            value={this.state.placeName}
            onChangeText={this.placeNameChangeHandler}
            placeholder='Beautiful place' /&gt;
          &lt;Button title='Add' style={styles.placeButton} onPress={this.placeSubmitHandler} /&gt;
        &lt;/View&gt;
      );
    }
  };
  </code></pre>
  
  <p>Please someone help me to understand: it is possible to have one onChangeText method in React Native, like the professor from ReactJS did with onChange?</p>