FunctionComponet在哪判断的

来源:5-3 reconcilerChildren

诺巴蒂

2021-03-09

export function createFiberFromTypeAndProps(
  type: any, // React$ElementType
  key: null | string,
  pendingProps: any,
  owner: null | Fiber,
  mode: TypeOfMode,
  expirationTime: ExpirationTime,
): Fiber {
  let fiber;

  let fiberTag = IndeterminateComponent;
  // The resolved type is set if we know what the final type will be. I.e. it's not lazy.
  let resolvedType = type;
  if (typeof type === 'function') {
    if (shouldConstruct(type)) {
      fiberTag = ClassComponent;
    }
  } else if (typeof type === 'string') {
    fiberTag = HostComponent;
  } else {
  //...

这里判断了 typeof type === function
但下面只判断了 ClassComponent 的类型:通过 shouldConstruct(type)
那 FunctionComponet在哪判断的?它确实就是个普通函数,返回的 ReactElement,这种也是合法的子节点呀

写回答

1回答

Jokcy

2021-03-12

在这里function component就是IndeterminateComponent类型,在后面渲染IndeterminateComponent的时候会再继续判断

0
0

React源码深度解析 高级前端工程师必备技能

掌握React源码,让你的开发水平没有上限,更不惧前端未来的到来

1749 学习 · 336 问题

查看课程