diff --git a/src/components/Render/index.js b/src/components/Render/index.js index 856d4d5..a866804 100644 --- a/src/components/Render/index.js +++ b/src/components/Render/index.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useRef, useCallback, useEffect } from 'react'; import PropTypes from 'prop-types'; import nodeTypes from 'rendering/types'; @@ -40,48 +40,40 @@ const render = (data, key) => { ; }; -class Render extends React.PureComponent { - static propTypes = { - data: PropTypes.object.isRequired, - onRender: PropTypes.func.isRequired - } +const Render = ({ data, onRender }) => { + const svgContainer = useRef(); - svgContainer = React.createRef() - - componentDidMount() { - this.provideSVGData(); - } - - componentDidUpdate() { - this.provideSVGData(); - } - - provideSVGData() { - if (!this.svgContainer.current) { + const provideSVGData = useCallback(() => { + if (!svgContainer.current) { return; } - const svg = this.svgContainer.current.querySelector('svg'); - this.props.onRender({ + const svg = svgContainer.current.querySelector('svg'); + onRender({ svg: svg.outerHTML, width: Number(svg.getAttribute('width')), height: Number(svg.getAttribute('height')) }); - } + }, [svgContainer, onRender]); - render() { - const { data } = this.props; + useEffect(() => { + provideSVGData(); + }, [provideSVGData]); - return