我已经寻找了一段时间,希望能够得到一个好的解释,以便让我彻底明白。
示例:<Char click={()=>this.onDeleteHandler(index)}/>
vs
<Char click={this.onDeleteHandler()}/>
vs
<Person changed={(event) => this.nameChangedhandler(event, person.id)} />
并且
<Char click={this.onDeleteHandler}/>
关于第三个代码,这里有一个叫做的属性:
nameChangedhandler = (event, id) => {
const personIndex = this.state.persons.findIndex(p => {
return p.id === id;
});
// copying the person with the right index
const person = {
...this.state.persons[personIndex]
};
// Assigning new name to this person
person.name = event.target.value;
// copying array of persons, then manipulating the correct object of person by using the index
const persons = [...this.state.persons];
persons[personIndex]= person;
this.setState({
persons: persons
});
我知道一些相关内容,但肯定不是100%!如果你能提供解释、链接或类似的东西,那就太好了!
谢谢!
this
。 - Alnitak