We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 79a61e7 commit c6441dfCopy full SHA for c6441df
src/mini-react/fiber.js
@@ -0,0 +1,14 @@
1
+let nextUnitOfWork = null;
2
+let rootFiber = null;
3
+
4
+// 创建 rootFiber 作为首个 nextUnitOfWork
5
+export function createRoot(element, container) {
6
+ rootFiber = {
7
+ stateNode: container, // 记录对应的真实 dom 节点
8
+ element: {
9
+ // 挂载 element
10
+ props: { children: [element] },
11
+ },
12
+ };
13
+ nextUnitOfWork = rootFiber;
14
+}
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
0 commit comments