1.2.0 • Published 6 years ago

react-jumpgate v1.2.0

Weekly downloads
17
License
MIT
Repository
github
Last release
6 years ago

react-jumpgate

A generic implementation of portals for React, for platforms where ReactDOM is not available (eg. this could be used in a React Native application to add buttons to the toolbar from any component in the tree)

import createJumpgate from 'react-jumpgate';

// A jumpgate is made of 3 components: an anchor, a consumer and a provider
const { Anchor, Consumer, Provider } = createJumpgate();

const App = () => (
    <div class="app">
        {/* Place the anchor near the root of your component tree */}
        <Anchor>
            <div class="header">
                {/* The consumer acts as a placeholder for the component you want to teleport */}
                <Consumer />
            </div>
            <div class="content">
                {/* The provider will send its children through the jumpgate to the consumer */}
                <Provider>
                    <h1>Title</h1>
                </Provider>
            </div>
        </Anchor>
    </div>
);

/* <App /> will render as
    <div class="app">
        <div class="header">
            <h1>Title</h1>
        </div>
        <div class="content" />
    </div>
*/
1.2.0

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago