0.1.4 • Published 3 years ago

@robingoupil/react-srm-wrapper v0.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Table of contents

Quick start

Install @robingoupil/react-srm-wrapper:

  • with npm: npm install -S @robingoupil/react-srm-wrapper
  • with yarn: yarn add @robingoupil/react-srm-wrapper

Create a loader component for your SRM.
We will assume that:

  • the asset-manifest.json file url is stored in .env
  • once loaded, the SRM render() function is exposed in window.myOrg.myModule
  • the module will be served with the relative path /my-module

MyModuleLoader.tsx

import React from 'react'
import { ReactSRMWrapper } from '@robingoupil/react-srm-wrapper';

const MyModuleLoader = () => {
  return (
    <>
      <h2>React SRM wrapper</h2>
      <ReactSRMWrapper assetManifestUrl={process.env.REACT_APP_ASSET_MANIFEST_URL!} exportPath="myOrg.myModule" basename="/my-module" />
    </>
  )
};

export default MyModuleLoader;

Expose the loader in your router (example for React Router)

API Reference

ReactSRMWrapper

SelectorReactSRMWrapper

Inputs

assetManifestUrlType: string URL to the asset-manifest.json.
exportPathType: string Path to the exported render() function once the module has been loaded.
basenameType: string Default value: / Relative path the module is being served from.
languageType: string Default value: en Language used for i18n.
argumentsType: object Default value: {} Extra arguments to pass to the render() function.
eventHandlersType: object Default value: {} Custom events that can be called by the SRM.

Outputs

loadedType: (el: HTMLElement) => any Emits an event when the module has been loaded.
renderedType: (args: any) => any Emits an event when the module has been rendered.