# @chakra-ui/portal

> React component used to render children outside the DOM hierarchy of the parent component

Latest version **2.1.0** (published 2023-07-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install @chakra-ui/portal
pnpm add @chakra-ui/portal
yarn add @chakra-ui/portal
bun add @chakra-ui/portal
```

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; popular repo.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2023-07-18 |
| First published | 2020-06-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 49.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 40648 |
| Author | Segun Adebayo |
| Maintainers | segunadebayo, _codebender828 |
| Keywords | react, portal, nested portal, z-index, layer, chakra ui |

## Links

- npm: https://www.npmjs.com/package/@chakra-ui/portal
- Repository: https://github.com/chakra-ui/chakra-ui
- Homepage: https://github.com/chakra-ui/chakra-ui#readme
- Issues: https://github.com/chakra-ui/chakra-ui/issues
- npm.io page: https://npm.io/package/@chakra-ui/portal

## Dependencies (2)

- [@chakra-ui/react-context](https://npm.io/package/@chakra-ui/react-context.md) 2.1.0
- [@chakra-ui/react-use-safe-layout-effect](https://npm.io/package/@chakra-ui/react-use-safe-layout-effect.md) 2.1.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.1.0 (latest) — 2023-07-18
- 0.0.0-dev-20230718132637 (dev) — 2023-07-18
- 2.0.0-next.3 (next) — 2022-05-09
- 0.0.0-pr-202212011232 (pr) — 2022-02-20
- 1.0.0-next.0 (canary) — 2020-06-20
- 0.0.0-dev-20230718130742 — 2023-07-18
- 0.0.0-dev-20230718124717 — 2023-07-18
- 0.0.0-dev-20230718122336 — 2023-07-18
- 2.0.16 — 2023-03-23
- 0.0.0-dev-20230320184810 — 2023-03-20
- 0.0.0-dev-20230320183136 — 2023-03-20
- 2.0.15 — 2023-01-16
- 0.0.0-dev-20230116124502 — 2023-01-16
- 0.0.0-dev-20230116122157 — 2023-01-16
- 0.0.0-dev-20230116120206 — 2023-01-16
- … 305 more at https://npm.io/package/@chakra-ui/portal/versions

## README

# @chakra-ui/portal

A wrapper for rendering components in React Portals, with support for nested
portals and stacking.

## Installation

```sh
yarn add @chakra-ui/portal

# or

npm i @chakra-ui/portal
```

## Import components

```jsx
import { Portal, PortalManager } from "@chakra-ui/portal"
```

Render the `PortalManager` once at the root of your application

```jsx
function App() {
  return (
    <ThemeProvider>
      <CSSReset />
      <PortalManager>{/* Your app goes here  */}</PortalManager>
    </ThemeProvider>
  )
}
```

### Basic usage

Portals are render into the portal manager's node by default not
`document.body`.

```jsx
<div>
  <p>Welcome</p>
  <Portal>This text has been portaled</Portal>
</div>
```

### Nested portals

Nesting portal can be very useful to build complex widgets like nested menu,
popovers, modal, etc.

```jsx
<Portal>
  This is a portal.
  <Portal>This is a nested portal</Portal>
</Portal>
```

### Custom container

You can also portal elements into a custom containers. Simply pass a
`containerRef` prop that points to the `node` of that element.

```jsx
<>
  <div ref={ref} />
  <Portal containerRef={ref}>
    <h1>Hello world</h1>
  </Portal>
</>
```

---
_Source: https://npm.io/package/@chakra-ui/portal · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
