subapp-react

1.3.0 • Public • Published

Electrode Subapp For React

This module mainly serve to setup subapp-web with Facebook React framework.

It basically re-exports the module subapp-web and sets it up with React specific APIs.

For convenience, it also exports the module react.

To use, a subapp's code should be doing:

import { React, loadSubApp } from "subapp-react";

import Component from "./component";

export default loadSubApp({ name: "MyComponent", Component });

For all pratical purposes, if there's code somewhere else that ensures subapp-web is setup with the proper React framework, then it's equivalent to the following:

import React from "react";
import { loadSubApp } from "subapp-web";

import Component from "./component";

export default loadSubApp({ name: "MyComponent", Component });

react and react-dom are specified as peerDependencies, so you must install them as part of your package.json dependencies.

SSR App Context

This module also exports a default React context that SSR uses to pass in server request object to your React component.

ie:

import { AppContext } from "subapp-react";

const Component = () => {
  return (
    <AppContext.Consumer>
      {({ isSsr, ssr, subApp }) => {
        return (
          <div>
            IS_SSR: {`${Boolean(isSsr)}`} HAS_REQUEST: {ssr && ssr.request ? "yes" : "no"}
          </div>
        );
      }}
    </AppContext.Consumer>
  );
};

Support for React Router

If you want to use react-router in your application, then you need to install the dependencies:

ie:

npm i react-router react-router-dom

And then set the useReactRouter flag to true in your subapp:

import { React, loadSubApp } from "subapp-react";

export default loadSubApp({ name: "MySubapp", Component, useReactRouter: true });

License

Copyright (c) 2016-present, WalmartLabs

Licensed under the Apache License, Version 2.0.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.3.03latest

Version History

VersionDownloads (Last 7 Days)Published
1.3.03
1.2.01
1.1.10
1.1.00
1.0.10
1.0.00
0.1.10
0.1.00
0.0.430
0.0.420
0.0.410
0.0.400
0.0.390
0.0.380
0.0.370
0.0.360
0.0.350
0.0.340
0.0.330
0.0.320
0.0.310
0.0.300
0.0.290
0.0.280
0.0.270
0.0.260
0.0.250
0.0.240
0.0.230
0.0.220
0.0.210
0.0.200
0.0.190
0.0.180
0.0.170
0.0.160
0.0.150
0.0.140
0.0.131
0.0.120
0.0.110
0.0.100
0.0.90
0.0.80
0.0.70
0.0.60
0.0.50
0.0.40
0.0.30

Package Sidebar

Install

npm i subapp-react

Weekly Downloads

5

Version

1.3.0

License

Apache-2.0

Unpacked Size

25.1 kB

Total Files

19

Last publish

Collaborators

  • jchip
  • arunvishnun
  • divyakarippath
  • chandub
  • srinathm85