阅读 3

React 深入学习:ReactPortal

path: packages/shared/ReactPortal.js

源码

import {REACT_PORTAL_TYPE} from 'shared/ReactSymbols';

import type {ReactNodeList, ReactPortal} from 'shared/ReactTypes';

export function createPortal(
  children: ReactNodeList,
  containerInfo: any,
  // TODO: figure out the API for cross-renderer implementation.
  implementation: any,
  key: ?string = null,
): ReactPortal {
  return {
    // 这个标记惟一地将该对象标识为 React Portal
    $$typeof: REACT_PORTAL_TYPE,
    key: key == null ? null : '' + key,
    children,
    containerInfo,
    implementation,
  };
}
复制代码

createPortal 方法返回一个 $$typeof 属性为 REACT_PORTAL_TYPE 的对象。

其他

ReactPortal

path: packages/shared/ReactTypes.js

export type ReactPortal = {
  $$typeof: Symbol | number,
  key: null | string,
  containerInfo: any,
  children: ReactNodeList,
  // TODO: figure out the API for cross-renderer implementation.
  implementation: any,
};
复制代码
关注下面的标签,发现更多相似文章
评论