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

@one-view/plugin-loader-react

v2.3.0

Published

Load another reactjs app as plugin

Downloads

5

Readme

Purpose

Allow a ReactJS app to be dynamically loaded as a plugin. Also provide a ReactJS component to load the plugin.

Usage

Preparing the ReactJS App Plugin

Add the following lines to your src/index.js file. The purpose of these lines is to create an entry point to render and unmount the ReactJS app. Once added you may notice that npm start will render a blank page instead. Follow the next section to restore the behavior of npm start to allow running the ReactJS app locally.

src/index.js

import { bootstrap } from 'plugin-loader-react';

bootstrap('PLUGIN_NAME', App, 'v1.0.1');

Allow npm start to launch the app

The previous section would have moved the app entry point to a JavaScript function. To launch the app when we run npm start, we need to call the JavaScript when the app loads the first time. Add the following code to the public/index.html. Here we add a script section to call the entry point when the window loads.

public/index.html

Only needed if you wish to be able to run the web app when calling npm start

<body>
    <div id="entry" style="width: 100vw;height: 100vh;"></div>
    <script type="text/javascript">
        window.onload = () => {
            window.PLUGIN_NAME.render('entry');
        };
    </script>
</body>

Loading a plugin

Once we have prepare the ReactJS app as a plugin, other ReactJS app can now load them dynamically. The following code shows how we can load another plugin dynamically. You may pass in custom data in the detail property. The detail property will appear in the plugin. If no value is passed into the detail prop, it will be undefined.

The loader by default will retry loading the plugin 3 times. The number is configurable in retry prop.

Loading Another Plugin

import Loader from 'plugin-loader-react';

class AppView {
    render = () => {
        return (
            <Loader
                history={this.props.history}
                host={'https://www.plugin.location.com'}
                name={'PLUGIN_NAME'}
                detail={{ key1: 'value1' }}
                flags={[]}
                onError={this._handleLoadError}
                retry={5}
            />
        );
    };
}