react-tradingview-embed
Version:
React components for TradingView Embeds
38 lines (37 loc) • 1.43 kB
JavaScript
import React from "react";
const ForexHeatMap = (props) => {
const { widgetProps, widgetPropsAny } = props;
const ref = React.createRef();
React.useEffect(() => {
let refValue;
if (ref.current) {
const script = document.createElement("script");
script.src = "https://s3.tradingview.com/external-embedding/"
+ "embed-widget-forex-heat-map.js";
script.async = true;
script.type = "text/javascript";
script.innerHTML = JSON.stringify(Object.assign(Object.assign({ "width": 770, "height": 400, "currencies": [
"EUR",
"USD",
"JPY",
"GBP",
"CHF",
"AUD",
"CAD",
"NZD",
"CNY"
], "isTransparent": false, "colorTheme": "dark", "locale": "en" }, widgetProps), widgetPropsAny));
ref.current.appendChild(script);
refValue = ref.current;
}
return () => {
if (refValue) {
while (refValue.firstChild) {
refValue.removeChild(refValue.firstChild);
}
}
};
}, [ref, widgetProps, widgetPropsAny]);
return React.createElement("div", { ref: ref });
};
export default ForexHeatMap;