npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-transport

v0.0.1

Published

Transports your React component to the outside of React rendering tree.

Downloads

6

Readme

react-transport

Transports your React component to the outside of React rendering tree.

bootstrap

Unstable

This package is not stable. The API will be changed frequently. I don't recommend use in production.

Usage

Just wrap your React components with <Transport> and tell destination via to props.

import Transport from 'react-transport';

class MyComponent extends React.Component {
  render() {
    const { count } = this.props;
    return <div>
      <h2>Inside: {count}</h2>
      <Transport to="#outside">
        <h2>Outside: {count}</h2>
      </Transport>
    </div>;
  }
}

Examples

npm install

Bootstrap

Renders React components to detached DOM tree.

npm run bootstrap

Chrome extension for Gmail

Shows online status of Slack members in Gmail.

npm run gmail

gmail-1

gmail-2

Run test

npm run test:gmail

API

react-transport provides <Transport /> component.

<Transport />

to: string | HTMLElement [Required]

The destination of transportation. You can use CSS Selector to point it. The (real) HTML element is also acceptable.

replace: bool

This is a default behavior of transportation.

HTML and JSX
<body>
  <h1>React</h1>
  <div id="outside" />
</body>
<Transport append to="#outside">
  <span>Hello</span>
</Transport>
Result
<body>
  <h1>React</h1>
  <div id="outside">
    <div>
      <span>Hello</span>
    </div>
  </div>
</body>

append: bool

Please use this when you want to insert your React component to the end of the destination.

HTML and JSX
<body>
  <h1>React</h1>
  <div id="outside">
    <p>Bla Bla Bla</p>
  </div>
</body>
<Transport append to="#outside">
  <span>Hello</span>
</Transport>
Result
<body>
  <h1>React</h1>
  <div id="outside">
    <p>Bla Bla Bla</p>
    <div>
      <span>Hello</span>
    </div>
  </div>
</body>

prepend: bool

HTML and JSX
<body>
  <h1>React</h1>
  <div id="outside">
    <p>Bla Bla Bla</p>
  </div>
</body>
<Transport prepend to="#outside">
  <span>Hello</span>
</Transport>
Result
<body>
  <h1>React</h1>
  <div id="outside">
    <div>
      <span>Hello</span>
    </div>
    <p>Bla Bla Bla</p>
  </div>
</body>

wrapBy: string | function

You can change wrapper element by using this option. In default, your component is wrapped with div tag.

HTML and JSX
<body>
  <h1>React</h1>
  <div id="outside" />
</body>
<Transport to="#outside" wrapBy="ul">
  <li>Hello</li>
  <li>World</li>
</Transport>
Result
<body>
  <h1>React</h1>
  <div id="outside">
    <ul>
      <li>Hello</li>
      <li>World</li>
    </ul>
  </div>
</body>

If you pass a function, it will call with children as first argument.

HTML and JSX
<body>
  <h1>React</h1>
  <div id="outside" />
</body>
<Transport to="#outside" wrapBy={children => <ul className="dropdown" onClick={this.handleClick}>{children}</ul>}>
  <li>Hello</li>
  <li>World</li>
</Transport>
Result
<body>
  <h1>React</h1>
  <div id="outside">
    <ul class="dropdown">
      <li>Hello</li>
      <li>World</li>
    </ul>
  </div>
</body>

Caveat

<Transport /> component doesn't work for server-side rendering.

Author

Yuki Kodama / @kuy