/
githubmr
/
facebook-react
Обзор
Документация
Войти
/
githubmr
/
facebook-react
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
packages/react-devtools-shared/src/devtools/views/portaledContent.js
55 строк
2 KB
Jan Kassens
Update Flow to 0.266 (#34271)
22 авг 2025, 22:46
Не верифицирован
22 авг 2025, 22:46
05addfc
Код
Авторство
О чём код?
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow */ import * as React from 'react'; import {useContext} from 'react'; import {createPortal} from 'react-dom'; import ErrorBoundary from './ErrorBoundary'; import {StoreContext} from './context'; import ThemeProvider from './ThemeProvider'; export type Props = {portalContainer?: Element, ...}; export default function portaledContent( Component: component(...props: any), ): component(...props: any) { return function PortaledContent({portalContainer, ...rest}: Props) { const store = useContext(StoreContext); let children = ( <ErrorBoundary store={store}> <Component {...rest} /> </ErrorBoundary> ); if (portalContainer != null) { // The ThemeProvider works by writing DOM style variables to an HTMLDivElement. // Because Portals render in a different DOM subtree, these variables don't propagate. // So in this case, we need to re-wrap portaled content in a second ThemeProvider. children = ( <ThemeProvider> <div data-react-devtools-portal-root={true} style={{ width: '100vw', height: '100vh', containerName: 'devtools', containerType: 'inline-size', }}> {children} </div> </ThemeProvider> ); } return portalContainer != null ? createPortal(children, portalContainer) : children; }; }