大概大半年时间都在用react写项目,一直在笔记上零零星星地记录着,在新的一年即将到来之际,打算整理整理发出来。javascript
class
在 JSX 里要写成
className
,由于
class
在 JS 里是保留关键字。同理某些属性好比
for
要写成
htmlFor
。
class Counter extends Component { constructor(props) { super(props); this.state = { count: props.initialCount }; } render() { // ... } }
使用 ES6 语法,能够直接定义 defaultProps
这个类属性来替代,这样能更直观的知道 default props 是预先定义好的对象值:html
Counter.defaultProps = { initialCount: 0 };
(1)componentWillMount
render
以前调用,你能够在这个方法里面调用
setState
改变状态,而且不会致使额外调用一次
render
(2)componentDidMount
render
以后调用,从这里开始能够经过
ReactDOM.findDOMNode(this)
获取到组件的 DOM 节点。
这些方法不会在首次 render
组件的周期调用java
componentWillReceiveProps
shouldComponentUpdate
componentWillUpdate
componentDidUpdate
statics
对象容许你定义静态的方法,这些静态的方法能够在组件类上调用;在这个块儿里面定义的方法都是静态的,意味着你能够在任何组件实例建立以前调用它们,这些方法不能获取组件的 props 和 state。若是你想在静态方法中检查 props 的值,在调用处把 props 做为参数传入到静态方法。
表单组件能够经过 onChange
回调函数来监听组件变化。当用户作出如下交互时,onChange
执行并经过浏览器作出响应:react
<input>
或 <textarea>
的 value
发生变化时。<input>
的 checked
状态改变时。<option>
的 selected
状态改变时。radio
、
checkbox
的
<input>
支持
defaultChecked
属性,
<select>
支持
defaultValue
属性。
this.props.key
from a component (eg. the render function) is not defined. If you need to access the same value within the child component, you should pass it as a different prop (ex: <ListItemWrapper key={result.id} id={result.id} />
).
ref
and key
) which are used by React, and are thus not forwarded to the component
<i style={{float:'right',marginRight:'7px'}} data-tip={__('仅供查询报警对象名称')} place="top" className="iconfont tips"></i>
即一些自定义的元素,最好使用 data- 放在开头。git
好了,本人不才,先到此为止。web