Skip to content

Commit

Permalink
三: 1.创建 nextUnitOfWork 和 rootFiber
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-lx committed Nov 10, 2021
1 parent 79a61e7 commit c6441df
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/mini-react/fiber.js
@@ -0,0 +1,14 @@
let nextUnitOfWork = null;
let rootFiber = null;

// 创建 rootFiber 作为首个 nextUnitOfWork
export function createRoot(element, container) {
rootFiber = {
stateNode: container, // 记录对应的真实 dom 节点
element: {
// 挂载 element
props: { children: [element] },
},
};
nextUnitOfWork = rootFiber;
}
5 changes: 3 additions & 2 deletions src/mini-react/react-dom.js
@@ -1,6 +1,7 @@
import { createRoot } from './fiber';

function render(element, container) {
const dom = renderDom(element);
container.appendChild(dom);
createRoot(element, container);
}

// 将 React.Element 渲染为真实 dom
Expand Down

0 comments on commit c6441df

Please sign in to comment.