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-outlet

v1.0.9

Published

Transclusion helpers for React.js

Downloads

729

Readme

React Outlet Travis npm package

Transclusion helpers for React.js

npm install react-outlet --save

React-Outlet provides two components which aid in cross-component transclusion for React.js, namely an Outlet and Plug component.

Outlets are tied to Plugs via an outletId property. There is a 1-1 relationship between an Outlet and Plug.

An example use-case is a parent page which contains two panels. One panel displays a child component while the other panel contains a couple of other components. Perhaps the parent wants to give the child component the ability to render an additional component in the side panel. Rather than pushing down the entire layout into the child (and potentially duplicating a ton of code between multiple children), with React-Outlet the parent can simply pass an outletId to the child. The child can then render arbitrary content into the parent's panel without loosing control (or causing additional renders).

All of this is done within the React lifecycle and is not async.

This same pattern can be used to build other complex components such as Modals or Tooltips.

Usage Example

var Outlet = require("react-outlet").Outlet;
var Plug = require("react-outlet").Plug;

var Parent = React.createClass({
    componentWillMount: function() {
        this.setState({
            header_outlet: Outlet.new_outlet_id()
        });
    },

    render: function() {
        return (
            <div>
                <Header>
                    Awesome parent
                    <Outlet outletId={ this.state.header_outlet } />
                </Header>
                <Child outlet={ this.state.header_outlet } />
            </div>
        );
    }
});

var Child = React.createClass({
    render: function() {
        return (
            <div>
                I am the child
                <Plug outletId={ this.props.outlet }>
                    I will appear in the header.
                </Plug>
            </div>
        );
    }
});

Component API

Static Methods:

Outlet.new_outlet_id()
    Generate and return a new outlet id.  Should be passed into Outlet and Plug
    components as the outletId prop.
    
Outlet.reset()
    Reset the Outlet's registry.  This was added for server-side React usage.

Components:

<Outlet outletId={ outlet_id } />
    Render an outlet somewhere in the React component tree.  By default this
    will render into an empty <div />.  Any props other than outletId will be
    passed to the underlying <div /> so the outlet is easily classable.

    The outletId prop ties this Outlet to a Plug.

<Plug outletId={ outlet_id }>{ ... children go here ... }</Plug>
    When a plug has children the children will appear in the associated Outlet
    (associated means the outlet has the same outletId as this plug).  You can
    still use all of the normal React features such as event listeners and so on
    on the Plug's children.

Related work in the React.js community

I want to give a shout out to Joe Critchley (@joecritchley) who had some great ideas for various outlet/portal implementations. Here are some links to his various implementations:

  • with-outlets.js (https://gist.github.com/joecritch/8755865)
    • A great example of how to give a parent component more fine-grained control of a components children.
  • Better component transclusion (http://joecritchley.svbtle.com/transclusion-in-react)
    • A blog post about something similar to with-outlets.js
  • "Portals" in React.js (http://joecritchley.svbtle.com/portals-in-reactjs)
    • An implementation of outlets similar to React-Outlet which uses DOM injection to transfer children around.