# react-app-loader

> Small utility function to inject a new react app into the DOM.

Latest version **1.2.0** (published 2021-03-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-app-loader
pnpm add react-app-loader
yarn add react-app-loader
bun add react-app-loader
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2021-03-04 |
| First published | 2021-01-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Adam Trincas |
| Maintainers | atrincas |
| Keywords | react, app, loader |

## Links

- npm: https://www.npmjs.com/package/react-app-loader
- Repository: https://github.com/atrincas/react-app-loader
- Homepage: https://github.com/atrincas/react-app-loader#readme
- Issues: https://github.com/atrincas/react-app-loader/issues
- npm.io page: https://npm.io/package/react-app-loader

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2021-03-04
- 1.1.1 — 2021-01-19
- 1.1.0 — 2021-01-18

## README

# react-app-loader

Small utility function to inject a new react app into the DOM.

## Why?

If for any reason you want to use multiple react-apps concurrently.

## How it works

- Fetches a react-app from the given url.
- After that it will inject the react-app script into the DOM.
- If needed, it can append a div element where the app will be mounted.

## Installation

npm:

```bash
npm i react-app-loader
```

or yarn:

```bash
yarn add react-app-loader
```

## Usage

This is the most basic example of how you can use the react-app-loader.

```javacript
import { loadApp } from 'react-app-loader'

// Inside your main react-app:

const [loading, setLoading] = useState(false)
const handleLoadApp = async () => {
  setLoading(true)
  const loaded = await loadApp('https://wwww.example.com/app-2','app-2')
  if (loaded) {
    setLoading(false)
  }
}

if (loading) {
  // You can show a loading spinner
  return <RandomLoadingSpinner />
}

  return (
    <div id="app-1">
    <h1>
      This is the main React app
    </h1>
    <button onClick={handleLoadApp}>Load second App</button>
    </div>
    <div id="app-2"></div>
  )
}


// The rest of your react-app:


```

## API Methods

```
loadApp(url, appId, [options]) => promise<true>

removeApp(appId): Removes the app script and its container element

removeAppScript(appId): Removes only the app script
```

## API Arguments

```
url: string

appID:string (The same id of the div element where the react-app will be mounted)

options?: {
  appendDiv: boolean
}

```

---
_Source: https://npm.io/package/react-app-loader · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
