| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | * |
| 7 | * @flow |
| 8 | */ |
| 9 | |
| 10 | import {REACT_PORTAL_TYPE, REACT_OPTIMISTIC_KEY} from 'shared/ReactSymbols'; |
| 11 | import {checkKeyStringCoercion} from 'shared/CheckStringCoercion'; |
| 12 | |
| 13 | import type { |
| 14 | ReactNodeList, |
| 15 | ReactPortal, |
| 16 | ReactOptimisticKey, |
| 17 | } from 'shared/ReactTypes'; |
| 18 | |
| 19 | export function createPortal( |
| 20 | children: ReactNodeList, |
| 21 | containerInfo: any, |
| 22 | // TODO: figure out the API for cross-renderer implementation. |
| 23 | implementation: any, |
| 24 | key: ?string | ReactOptimisticKey = null, |
| 25 | ): ReactPortal { |
| 26 | let resolvedKey; |
| 27 | if (key == null) { |
| 28 | resolvedKey = null; |
| 29 | } else if (key === REACT_OPTIMISTIC_KEY) { |
| 30 | resolvedKey = REACT_OPTIMISTIC_KEY; |
| 31 | } else { |
| 32 | if (__DEV__) { |
| 33 | checkKeyStringCoercion(key); |
| 34 | } |
| 35 | resolvedKey = '' + key; |
| 36 | } |
| 37 | return { |
| 38 | // This tag allow us to uniquely identify this as a React Portal |
| 39 | $$typeof: REACT_PORTAL_TYPE, |
| 40 | key: resolvedKey, |
| 41 | children, |
| 42 | containerInfo, |
| 43 | implementation, |
| 44 | }; |
| 45 | } |