title: How can i initialize state by passing props from parent component to child component in ReactJS?
body: <p>I am trying to initialize state in child component <strong>(EditUser)</strong> by passing props from below parent component <strong>(App)</strong>:</p>
  
  <pre><code>class App extends React.Component{
  state = { name: '', city: '', company: ''};
  inApp = async (name,city,company) =&gt;{
         await this.setState({name: name, city: city, company:company});
       }
  render(){
      return(
  
          &lt;div className="ui container grid"&gt;
               &lt;div className="ui row"&gt;
                   &lt;div className="column eight wide"&gt;
                      &lt;UserList inApp={this.inApp}/&gt;
                   &lt;/div&gt;
                  &lt;div className="column eight wide"&gt;
                      &lt;EditUser sendState={this.state}/&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;   
         ); 
      };
  };
  </code></pre>
  
  <p>Below is the <strong>EditUser</strong> component:</p>
  
  <pre><code>class EditUser extends React.Component{
          state = {term: this.props.sendState.name, city: this.props.sendState.city, company: this.props.sendState.company};
          change = () =&gt; {
              this.props.change(this.state.term, this.state.city, this.state.company);
          }
  
          render(){
             return (
                  &lt;div className="ui form"&gt;
  
                      &lt;h3 className="ui dividing header"&gt;Edit User&lt;/h3&gt;
                      &lt;div className="field"&gt;
                          &lt;label&gt;Name&lt;/label&gt;
                          &lt;input type="text" name="name"  value = {this.state.term} onChange={e=&gt;this.setState({term:e.target.value})} placeholder={this.props.user.name}/&gt;
                      &lt;/div&gt;
                     &lt;button className="ui green button" onClick={this.change}&gt;Submit&lt;/button&gt;                 
                &lt;/div&gt;  
              );
          }
  };
  const mapStateToProps=(state)=&gt;{
  
      return {
          user: state.list.SelectUser
      };
  }
  export default connect(mapStateToProps, {change : change})(EditUser);
  </code></pre>
  
  <p>I want to initialize the state in above component.<br>
  <strong>How can i do so?</strong></p>