[JSX 코드] → CreateElement → [VNode(실제로는 ReactElement)] → Render Phase(Virtual DOM 구조 또는 Fiber Tree 생성) → Commit Phase (실제 DOM 반영)
사실 이 부분이 제일 이해가 잘 안되었는데요… 그래서 다른 코드들을 참고 + AI랑 열심히 공부했습니다
createElement 안에서 3개 이상의 params을 받을 때 분기 처리?
export function createElement(type, props, children) {
let normalizedProps = {},
key,
ref,
i;
for (i in props) {
if (i == 'key') key = props[i];
else if (i == 'ref' && typeof type != 'function') ref = props[i];
else normalizedProps[i] = props[i];
}
if (arguments.length > 2) {
normalizedProps.children =
arguments.length > 3 ? slice.call(arguments, 2) : children;
}
return createVNode(type, normalizedProps, key, ref, NULL);
}
NormalizeNode의 역할?
<div>
{null}
{undefined}
{false}
{"text"}
{123}
{[1, 2, <span />]}
<Child />
</div>
Fiber 기반으로 변경사항을 DOM에 반영하는 과정
전체 과정
beforeMutation → mutation → layout