`npm install --save @abtasty-innovation/react-module-injection`
npm install @abtasty-innovation/react-module-injectionnpm install --save @abtasty-innovation/react-module-injection
To run a JS as a module from a react component, do the following :
``js
import React, { Component } from "react";
import { ModuleWrapper } from "@abtasty-innovation/react-module-injection";
class Reporting extends Component {
constructor(props) {
super(props);
this.state = {
iframeHeight: 400,
data: {
initial: true
},
abData: {
accessToken: "...",
accountId: "..."
}
};
}
render() {
return (
srcUrl="./component.js"
name="ModuleTest"
moduleData={this.state.data}
abData={this.state.abData}
onEvent={(name, data) =>
console.log(event name ${name} triggerd with ${data})`
}
onInjected={() => console.log("Module injected")}
onWait={() => console.log("Module sent wait !")}
onReady={() => console.log("Module sent ready !")}
onUpdatedHeight={e => {
console.log("Module height updated to : ", e);
this.setState({
iframeHeight: e
});
}}
style={{ height: this.state.iframeHeight + "px" }}
/>
);
}
}
To create a react component that is wrapped as a module, just wrap you component with the inject HOC :
`js
import React, { Component } from "react";
import { inject } from "@abtasty-innovation/react-module-injection";
class ModuleTest extends Component {
constructor(props) {
super(props);
}
render() {
return (
export default inject(ModuleTest);
``