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的时候会再继续判断
00
相似问题