ReactJS modify parent state from child component

烈酒焚心 提交于 2019-12-02 20:57:36

React actually auto-binds methods to the current component:

http://facebook.github.io/react/blog/2013/07/02/react-v0-4-autobind-by-default.html

In the TodoList component, rather than:

scope.props.onRemoveItem.bind(this, i)

Try:

scope.props.onRemoveItem.bind(null, i)

By providing null instead of this you'll allow React to do its own thing. Also you need to actually use the onClick handler:

<li onClick={this.props.onClick}>{this.props.task}</li>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!