I am trying to experiment with React, I have a problem updating status values ββfor a specific key.
Here is my condition
this.state = { connections : { facebook : "http://facebook.com", flickr : null, foursquare : null, googleplus : null, id : 0, instagram : "http://instagram.com/", openstreetmap : null, pinterest : null, place_id : 1, tomtom : null, tripadvisor : null, twitter : "http://twitter.com", vimeo : null, wikipedia : null, yelp : null, youtube : null }, contact : { } }
I call the external component and send parameters to it.
<Connection type="Facebook" icon={facebookIcon} placeholder="Add Facebook Link" name="facebook" value={this.state.connections.facebook} onChange={this.handleChange.bind(this)}/> <Connection type="Twitter" icon={twitterIcon} placeholder="Add Twitter Link" name="twitter" value={this.state.connections.twitter} onChange={this.handleChange.bind(this)}/> <Connection type="Instagram" icon={instagramIcon} placeholder="Add Instagram Link" name="instagram" value={this.state.connections.instagram} onChange={this.handleChange.bind(this)}/>
Component in an external file:
<input type="text" name={this.props.name} placeholder={this.state.placeholder} value={this.props.value} onChange={this.props.onChange} />
When changing a value in a text box
handleChange(e) { this.setState({ connections : {[e.target.name]: e.target.value} }) }
While I try to change any field values, it sets the rest 2 with empty. For example, if I try to edit the Facebook text box, it will set the values ββof Twitter and Instagram.
Can I find out what I am doing wrong in setting handleChange? I'm sure something is wrong with this.setState , but not sure how to target a specific key value.