Easily integrate SRM into your React application
Install @nicecactus/react-srm-wrapper:
- with npm:
npm install -S @nicecactus/react-srm-wrapper - with yarn:
yarn add @nicecactus/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 inwindow.myOrg.myModule - the module will be served with the relative path
/my-module
importReactfrom'react'import{ReactSRMWrapper}from'@nicecactus/react-srm-wrapper';constMyModuleLoader=()=>{return(<><h2>React SRM wrapper</h2><ReactSRMWrapperassetManifestUrl={process.env.REACT_APP_ASSET_MANIFEST_URL!}exportPath="myOrg.myModule"basename="/my-module"/></>)};exportdefaultMyModuleLoader;Expose the loader in your router (example for React Router)
| Selector | ReactSRMWrapper |
assetManifestUrl | Type: stringURL to the asset-manifest.json. |
exportPath | Type: stringPath to the exported render() function once the module has been loaded. |
basename | Type: stringDefault value: /Relative path the module is being served from. |
language | Type: stringDefault value: enLanguage used for i18n. |
arguments | Type: objectDefault value: {}Extra arguments to pass to the render() function. |
eventHandlers | Type: objectDefault value: {}Custom events that can be called by the SRM. |
loaded | Type: (el: HTMLElement) => anyEmits an event when the module has been loaded. |
rendered | Type: (args: any) => anyEmits an event when the module has been rendered. |