React 通过dom获取fiber

源码目录:react/packages/react-dom/src/client/ReactDOMComponentTree.js

const randomKey = Math.random()
  .toString(36)
  .slice(2);
const internalInstanceKey = '__reactInternalInstance$' + randomKey;
export function precacheFiberNode(hostInst, node) {
  node[internalInstanceKey] = hostInst;
}

因此dom对象上存储的fiber的属性名是__reactInternalInstance$开头的随机字符串

posted @ 2022-01-15 17:37  IslandZzzz  阅读(262)  评论(0编辑  收藏  举报