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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-layer

v2.0.0

Published

Simple abstraction for creating and managing new render trees

Readme

react-layer

Simple abstraction for creating and managing new render trees

Install

npm i -S react-layer

Use

A Layer is a simple class that manages the mounting and unmounting of a ReactElements to a specific container element. This is helpful for when, in the course of a react heirarchy you need to append a component outside of the current render tree. The canonical example of this pattern is overlays or modals that need to be appended to the document body.

Simply put this sort of like the React equivalent to jquery's appendTo ($('node').appendTo('body'))

new Layer(container, renderFn)

The Layer object takes two arguments: a container, which is a DOM node that the layer will be mounted too (such as the document.body), and render, a function that, when called, returns a ReactElement to render into the container

Layer.render(cb, parentComponent)

Mounts and Renders the return value of the function provided in the constructor (renderFn) to the container

Takes two optional arguments: cb, a callback that will be called after the layer has been rendered, and a parentComponent, which is a React Component that is the conceptual parent of the layer. If parentComponent is provided, its React context will be passed along to the layer.

Layer.unmount()

Unmounts the component from the container, but leaves the mount point node in the DOM.

Layer.destroy()

Unmounts, and removes all traces of the layer from the container. This calls unmount() so there is no need to call it in addition to destroy.

var Layer = require('react-layer')
var Modal = require('some-modal-component')

// here is a simple async alert()
function alert(message, callback) {
  var layer = new Layer(document.body, function renderModal(){
        return (
          <Modal show onHide={finish}>
            <Modal.Body>
              <h4>{message}</h4>
            </Modal.Body>
            <Modal.Footer>
              <button onClick={finish}>Close</button>
            </Modal.Footer>
          </Modal>
        )
      })

  // actually renders our Modal off of the document.body
  layer.render()

  function finish(){
      callback()
      layer.destroy() // unmount and remove the React Component tree
  }
}

alert('hello there!')

If you want to create a component that represents the layer you can do that with a fairly simple Higher Order Component. The below example will tie the lifecycle of the Layer with the component that creates it. You can just provide a render method and the HOC will ensure that it is created and rendered at the right time.


let createLayeredComponent = render => class extends React.Component {

  static propTypes = {
    container: React.PropTypes.any
  }

  componentWillUnmount () {
    this._layer.destroy()
    this._layer = null
  }

  componentDidUpdate() {
    this._renderOverlay();
  }

  componentDidMount() {
    this._renderOverlay();
  }

  _renderOverlay() {
    if (!this._layer)
      this._layer = new Layer(this.props.container || document.body, () => this._child)

    this._layer.render()
  }

  render() {
    this._child = render(this.props) //create the elements in render(), otherwise Owner can be lost
    return null;
  }
}

// and In use....

var LayeredComponent = createLayeredComponent(function(props){
  return (
    <MyComponentIWantRenderedInALayer {...props}>
      {props.children}
    </MyComponentIWantRenderedInALayer>
  )
})