React hook to execute or load scripts inside element with html provided by dangerouslySetInnerHTML
npm install react-html-script-evalReact hook to execute or load scripts inside element with html provided by dangerouslySetInnerHTML. It'll mount scripts within the component provided by react ref and execute scripts with correct document.currentScript property.
``bash`
$ npm i react-html-script-eval
`js
import { useHtmlScriptEval } from "react-html-script-eval";
useHtmlScriptEval(
html: string,
ref: RefObject
) => void;
`
`js
import React, { FC, useRef } from 'react';
import { useHtmlScriptEval } from 'react-html-script-eval';
interface AdBannerProps {
html: string;
}
const AdBanner: FC
const ref = useRef < HTMLDivElement > null;
useHtmlScriptEval(html, ref);
return
;export default AdBanner;
`
`bash``
$ npm run test