React的导出:
createElement
react对外导出的方法
createElementWithValidation
使用验证创建元素
isValidElementType
判断是否是有效的元素类型,源码:github.com/facebook/re…
createElement
创建并返回给定类型的新ReactElement。参考:reactjs.org/docs/react-…
这里使用createElementWithValidation的this和arguments替换createElement的this和arguments。
hasValidRef
判断config是否具有有效的ref,参考:github.com/facebook/re…
warnIfStringRefCannotBeAutoConverted
如果字符串引用无法自动转换,则发出警告(只在开发环境下使用),参考:github.com/facebook/re…
hasValidKey
判断config是否有有效key,参考:github.com/facebook/re…
RESERVED_PROPS
预留props,默认props
ReactElement
创建新的react元素。
总结步骤(createElement):
- 创建props,判断config,config存在就就给props赋值,ref(校验),key(校验),self,source,等。
- 把children跟后面可能会传的值统一组成赋值给props.children。
- 如果type有默认props(type.defaultProps),则将type.defaultProps赋值给props。
- 返回由ReactElement返回的对象
validateChildKeys
第三个参数之后参数验证(children,以及后面可能有的多个参数),参考:github.com/facebook/re…
validateExplicitKey
总结步骤(createElementWithValidation):
- 判断是否是有效的元素类型(type),不是有效的元素类型(type),将会抛出一些错误信息
- 使用createElement创建react对象(由$$typeof,type,key,ref,props,等一些属性组成的对象)
- 验证children,以及后面可能传过来的参数。(抛出一些错误)
- 验证props。(抛出一些错误)
- 返回刚刚创建的react对象。
// 待补充