React学习之高级顶配API说明(二十二)
如果环境中无法使用,则使用
我们可以写 createElement() createFactory()
cloneElement() isValidElement() React.Children
React.PropTypes
React.PropTypes.array
React.PropTypes.bool
React.PropTypes.func
React.PropTypes.number
React.PropTypes.object
React.PropTypes.string
React.PropTypes.symbol
React.PropTypes.node
React.PropTypes.element
React.PropTypes.instanceOf()
React.PropTypes.oneOf()
React.PropTypes.oneOfType()
React.PropTypes.arrayOf()
React.PropTypes.objectOf()
React.PropTypes.shape()
React.PropTypes.any
还可以通过
如果使用了 函数狂欢开始,之前提到的函数会稍微讲一下用处,算是一个总结
class Greeting extends React.Component {
render() {
return <h1>Hello,{this.props.name}</h1>;
}
}
当然之前博客也说了,
class Tmq extends React.PureComponent{
constructor(props){
super(props);
this.Exhandler = this.Exhandler.bind(this);
}
Exhandler(){
//this.forceUpdate();
}
render(){
console.log("render");
return <div onClick={this.Exhandler}>abcd</div>;
}
}
ReactDOM.render(
<Tmq/>,document.getElementById("root")
);
var Greeting = React.createClass({
render: function() {
return <h1>Hello,{this.props.name}</h1>;
}
});
前面非
React.createElement(
type,[props],[...children]
)
第一个参数为
React.cloneElement(
element,[...children]
)
复制一个
<element.type {...element.props} {...props}>{children}</element.type>
这个函数与
React.createFactory(type)
这个函数返回一个产生 这个函数也是会被抛弃的,所以建议使用 这个函数在前面的非
React.isValidElement(object)
检测对象是不是一个
提供了一系列操作
React.Children.map(children,function[(thisArg)])
第一个参数为某个 [在每一个直接子级(包含在
React.Children.forEach(children,function[(thisArg)])
和
React.Children.count(children)
返回组件子元素的总数量,其数目等于
React.Children.only(children)
返回唯一的子元素否则报错
React.Children.toArray(children)
返回一个由各子元素组成的数组,如果你想在
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |