React 随笔二

这周做的demo3和demo4、5 随记的小点。

1、js错误提示: Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `HelloMessage`. See https://fb.me/react-warning-keys for more information.

 
 
解决办法,给组件加个key属性,并赋值唯一key值用来标识。
2、state值改变——this.state.isVisible  或  this.setState({isVisible:true})
 
两种方式, this.setState() ----  及时刷新dom的时候,
                    this.state()  ----单独使用不能及时刷新dom,需要使用forceUpdate()
3、props  实现父组件传递数据到子组件
getDefaultProps:设置默认属性,返回一个对象
 
4、事件。直接使用value给input赋值,而不加onchange事件来监听的话。所得到的input只有你代码里设置的value值。用户不能直接改变input的值。可以用defaultValue而不是value来设置。或者加个onchange事件。
原文地址:https://www.cnblogs.com/marryZheng/p/5677466.html