我正在尝试遵循ReactJS教程,因为这是我第一次进入框架,尝试将其改编为我见过的另一种风格。
但是我似乎无法让以下工作。这是一个简单的type a name > click button > add to displayed list
应用程序,但在将样式更改为一个我感觉更舒服之后,我似乎无法获得添加。
答案 0 :(得分:0)
App组件中的addFriend
函数不会引用参数friend。此外,当您使用prevState
值更新状态时,请遵循setState
的更新程序函数语法。将其更改为
addFriend = (friend) => {
this.setState(prevState => ({
friends: prevState.friends.concat([friend])
}))
}
<强> Working codesandbox 强>