react笔记
1.关于 react的文章
- 一些小总结
- setState()不会马上改变状态。如果想获取改变后的值请使用回调函数,例如:this.setState({stat: “new”}, ()=>{console.log(this.state.stat)});
- 一般在componentDidMount中添加监听器,在componentWillUnmount中移除监听器。如果组件中还使用了setTimeout,setInterval,记得在componentWillUnmount移除。
- 关于错误:Warning: Each child in a list should have a unique “key” prop。很多人不重视这个错误,毕竟随便给数组里的组件加个唯一的key属性就好了嘛,但是如果你真的这么随便的敷衍的话,浏览器可能也会随便给你一个你无法理解的bug!详情参见:https://editor.csdn.net/md/?articleId=105401401