React源码-WorkInProgress常用操作
# 前言
总结归纳,在 React
中的常用操作
# 常用操作
// 获取 current 树
const current = workInProgress.alternate;
1
2
2
# 如何判断为 HOST
父类型
function isHostParent(fiber: Fiber):boolean {
return (
fiber.tag === HostComponent ||
fiber.tag === HostRoot ||
fiber.tag === HostPortal
)
}
1
2
3
4
5
6
7
2
3
4
5
6
7
# 如何判断为 HOST
父类型
判断 fiber
是否存在 DOM
结构:
const isHost = tag === HostComponent || tag === HostText;
1
# 如何跳过没有 DOM 结构的组件:
switch (workInProgress.tag) {
case IndeterminateComponent:
case LazyComponent:
case SimpleMemoComponent:
case FunctionComponent:
case ForwardRef:
case Fragment:
case Mode:
case Profiler:
case ContextConsumer:
case MemoComponent:
return null;
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
编辑 (opens new window)
上次更新: 2023/09/17, 22:09:00