You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

react-portal-minimal

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-portal-minimal

React component used to hoist components to a new subtree.

4.0.2
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

React-Portal-Minimal

npm version npm downloads Build Status

Demo

React-Portal-Minimal is a minimalistic version of React-Portal.

Compared to React-Portal, it is less than 1/3 the size, has minimal options, and no state.

It is intended as a building block. It does only three things:

  • Hoists its contents to a new React subtree.
  • Optionally sets a className on the subtree root.
  • Updates that className on the subtree root if it changes.

Features

  • Transports its child into a new React component and appends it to the document.body (creates a new independent React tree)
  • Doesn't leave any mess in DOM after unmount.
  • no dependencies
  • fully covered by tests

Installation

npm install react react-dom react-portal-minimal --save

Size

react-portalreact-portal-minimal
require() size7.3kB3.7kB
tarball size450kB4.2kB

Usage

import React from 'react';
import ReactDOM from 'react-dom';
import Portal from 'react-portal-minimal';

export default class App extends React.Component {

  render() {
    const button1 = <button>Open portal with pseudo modal</button>;

    return (
      <Portal>
        <PseudoModal>
          <h2>Pseudo Modal</h2>
          <p>This react component is appended to the document body.</p>
        </PseudoModal>
      </Portal>
    );
  }

}

export class PseudoModal extends React.Component {

  render() {
    return (
      <div>
        {this.props.children}
        <p><button onClick={this.props.closePortal}>Close this</button></p>
      </div>
    );
  }

}

ReactDOM.render(<App />, document.getElementById('react-body'));

Documentation - props

Required

children : ReactElement

The portal expects one child (<Portal><Child ... /></Portal>) that will be ported.

Optional

className: string

A className to apply to the new React tree's root.

Contribution

Please, create issues and pull requests.

git clone https://github.com/strml/react-portal-minimal
cd react-portal-minimal
npm install
npm start
open http://localhost:3000

Don't forget to run this before every commit:

npm test

Credits

This project is based on @tajo's react-portal.

That project: Vojtech Miksu 2015, miksu.cz, @vmiksu

Keywords

react

FAQs

Package last updated on 11 May 2017

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