1 React中有什么顶层API
|
|
控制台输出就是如下React对象
|
|
顶层API的一般用法
createElement( )
|
|
平常我们用 jsx 写的<Hello />
其实就是对CreateElement函数的封装
|
|
等价于
|
|
React.Component( )
|
|
2 ReactDOM
ReactDOM.render()
|
|
- 该方法将在我们提供的container中渲染一个React元素
- 如果可选择的callback被提供了,那么在组件渲染完毕之后,就可以执行callback函数
- React将会替换我们提供的container中的所有元素为ReactElement(如果原来的容器有子元素的话)
unmountComponentAtNode( )
|
|
Remove a mounted React component from the DOM and clean up its event handlers and state. If no component was mounted in the container, calling this function does nothing. Returns true
if a component was unmounted and false
if there was no component to unmount.
findDOMNode( )
|
|
If this component has been mounted into the DOM, this returns the corresponding native browser DOM element. This method is useful for reading values out of the DOM, such as form field values and performing DOM measurements. In most cases, you can attach a ref to the DOM node and avoid using findDOMNode at all. When render
returns null
or false
, findDOMNode
returns null
.