UNPKG

react-tradingview-embed

Version:
28 lines (27 loc) 1.15 kB
import React from "react"; const Timeline = (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-timeline.js"; script.async = true; script.type = "text/javascript"; script.innerHTML = JSON.stringify(Object.assign(Object.assign({ "colorTheme": "dark", "isTransparent": false, "displayMode": "regular", "width": 480, "height": 830, "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 Timeline;