Socket
Socket
Sign inDemoInstall

@reach/portal

Package Overview
Dependencies
3
Maintainers
2
Versions
53
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@reach/portal


Version published
Weekly downloads
507K
decreased by-0.44%
Maintainers
2
Install size
174 kB
Created
Weekly downloads
 

Package description

What is @reach/portal?

@reach/portal is a React component that allows you to render children into a DOM node that exists outside the DOM hierarchy of the parent component. This is useful for creating modals, tooltips, and other UI elements that need to visually break out of their container.

What are @reach/portal's main functionalities?

Basic Portal Usage

This example demonstrates the basic usage of the @reach/portal package. The `Portal` component is used to render a div outside of the parent DOM hierarchy, which can be useful for creating modals or tooltips.

import React from 'react';
import { Portal } from '@reach/portal';

function App() {
  return (
    <div>
      <h1>My App</h1>
      <Portal>
        <div style={{ position: 'absolute', top: 0, left: 0, background: 'white', border: '1px solid black' }}>
          This is rendered in a portal!
        </div>
      </Portal>
    </div>
  );
}

export default App;

Nested Portals

This example shows how you can nest portals within each other. The nested `Portal` component renders its children outside of the parent DOM hierarchy, allowing for complex UI structures.

import React from 'react';
import { Portal } from '@reach/portal';

function App() {
  return (
    <div>
      <h1>My App</h1>
      <Portal>
        <div style={{ position: 'absolute', top: 0, left: 0, background: 'white', border: '1px solid black' }}>
          This is rendered in a portal!
          <Portal>
            <div style={{ position: 'absolute', top: 20, left: 20, background: 'lightgray', border: '1px solid black' }}>
              This is a nested portal!
            </div>
          </Portal>
        </div>
      </Portal>
    </div>
  );
}

export default App;

Other packages similar to @reach/portal

FAQs

Last updated on 11 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc