Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-custom-portal

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-custom-portal

renders part of your component markup outside in some another place

  • 1.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
2
Weekly downloads
 
Created
Source

react-custom-portal

This helps you if you want to render part of your component markup in some another place. It's a bit like html portal in react, but for general react markup.

import { createPortal } from 'react-custom-portal'

const ExternalMarkup = createPortal()

const MyComponent = () => {
  <SomeMarkup>
    ...
    <ExternalMarkup.Content>
      This text will not be rendered here,
      but instead it will be rendered within ExternalMarkup.Render
    </ExternalMarkup.Content>
    ...
  </SomeMarkup>
}

const MySettings = () => {
  <AnotherMarkup>
    ...
    {/* The content of <ExternalMarkup.Content ... /> will be rendered here */}
    <ExternalMarkup.Render />
    ...
  </AnotherMarkup>
}

const MyPage = () => {
  <ExternalMarkup.Root>
    ...
    <MyComponent />
    ...
    <MySettings />
    ...
  </ExternalMarkup.Root>
}

By default <Portal.Render /> will render the content of all the <Portal.Content />s been rendered within the <Portal.Root />. If you want to tweak some things you can pass a function as the only child of <Portal.Render /> and it will be passed an array of <Portal.Content />s.

  ...
  <ExternalMarkup.Content shape="circle" ... />
  ...
  <ExternalMarkup.Content shape="rectangle" ... />
  ...
  <ExternalMarkup.Render>
    {children => children.filter(child => child.props.shape === "rectangle")}
  </ExternalMarkup.Render>
  ...

createPortal can be passed an options object with displayName prop to tune the names of created components for debug purpose.

const Objects3DSettings = createPortal({ displayName: "Objects3DSettings" })
// now react tools displays "Objects3DSettings.Content" for <Objects3DSettings.Content ... /> instead of "Portal.Content"

Keywords

FAQs

Package last updated on 19 Feb 2020

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc