React

358 阅读1分钟

创建element对象调用的函数栈

  • jsxWithValidation
  • jsxDEV
  • hasValidKey
  • hasValidRef
  • defineKeyPropWarningGetter
  • ReactElement
  • 遍历props.children调用validateChildKeys(children[i], type)
  • validatePropTypes

jsxWithValidation(jsx验证函数)

内部调用 jsxDEV(type, props, key, source, self)

  • type: 函数
  • props: 带有ref属性的对象
  • key: key值
  • source: 路径
  • self: undefined
  • 返回 element对象
  • 对象例子
{
   $$typeof: Symbol(react.element),
   "key":"key",
    "ref":"我是ref",
    "props":{
        "a":"a",
        "b":"b",
        "c":[1,23,3],
        "children": [
            0: "123456789",
            1: {"type":"div","key":null,"ref":null,"props":{"id":"id","children":{"type":"h1","key":null,"ref":null,"props":{"children":"children"},"_owner":null,"_store":{}}},"_owner":null,"_store":{}},
            2: {"type":"span","key":null,"ref":null,"props":{"children":"children2"},"_owner":null,"_store":{}}
        ]
        "_owner":null,
        "_store":{}
   }
}