Quantcast
Channel: User Just code - Stack Overflow
Viewing all articles
Browse latest Browse all 41

Answer by Just code for How to Create Unique Edit Fields for particular Item in React

$
0
0

You should consider changing it to object like this this way you can handle it easily and you do not have to maintain other properties.

skills: [{ id: "Frost Bolt", value: '' }, { id: "Arcane Missle", value: '' }],

when input changes try changing like this

  handleChangeSkills(event, element) {    this.setState({      skills: this.state.skills.map(a => {        if (a.id === element) {          a.value = event.target.Value;        }        return a;      })    });  }

leave your handlechange as it is

  handleChange(event, element) {    this.setState({      [element]:event.target.value    });  }

and call it in skills inputs like this

<input onChange={(e) => this.handleChangeSkills(e, val.id)} value={val.val} className={this.state.editIsHidden ? 'hidden' : ''} />

Here is the demo


Viewing all articles
Browse latest Browse all 41

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>