Utilities

门户

¥Portal

在 DOM 的不同部分渲染 React 子树。

Features

    Render any React subtree outside of your App.

    Appends to `document.body` by default but can be customized to use a different container.

安装

¥Installation

从命令行安装组件。

¥Install the component from your command line.

npm install @radix-ui/react-portal

结构

¥Anatomy

导入组件。

¥Import the component.

import { Portal } from "radix-ui";
export default () => <Portal.Root />;

基本示例

¥Basic example

使用门户基础组件。

¥Use the portal primitive.

import { Portal } from "radix-ui";
export default () => <Portal.Root>Content</Portal.Root>;

API 参考

¥API Reference

¥Root

你放入此组件中的任何内容都将在单独的 <div> 元素中渲染。默认情况下,此元素将附加到 document.body,但你可以使用 container 属性选择其他容器。

¥Anything you put inside this component will be rendered in a separate <div> element. By default, this element will be appended to document.body but you can choose a different container by using the container prop.

PropTypeDefault
asChild
boolean
false
container
HTMLElement
No default value