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,
};