diff --git a/components/Carbon.js b/components/Carbon.js index a3b7dbe..f1bcf5b 100644 --- a/components/Carbon.js +++ b/components/Carbon.js @@ -21,12 +21,11 @@ const Watermark = dynamic(() => import('../components/svg/Watermark'), { class Carbon extends React.PureComponent { static defaultProps = { onAspectRatioChange: () => {}, - onChange: () => {}, - innerRef: () => {} + onChange: () => {} } componentDidMount() { - const node = this.exportContainerNode + const node = this.props.innerRef.current this.mo = new MutationObserver(() => { const ratio = node.clientWidth / node.clientHeight this.props.onAspectRatioChange(ratio) @@ -66,11 +65,6 @@ class Carbon extends React.PureComponent { } } - getRef = ele => { - this.exportContainerNode = ele - this.props.innerRef(ele) - } - render() { const config = { ...DEFAULT_SETTINGS, ...this.props.config } @@ -228,7 +222,7 @@ class Carbon extends React.PureComponent { return (
-
+
{content}
@@ -257,4 +251,4 @@ class Carbon extends React.PureComponent { } } -export default Carbon +export default React.forwardRef((props, ref) => ) diff --git a/components/Editor.js b/components/Editor.js index fed9939..e3a9e5f 100644 --- a/components/Editor.js +++ b/components/Editor.js @@ -55,8 +55,6 @@ class Editor extends React.Component { this.resetDefaultSettings = this.resetDefaultSettings.bind(this) this.getCarbonImage = this.getCarbonImage.bind(this) this.onDrop = this.onDrop.bind(this) - - this.innerRef = node => (this.carbonNode = node) } async componentDidMount() { @@ -99,6 +97,8 @@ class Editor extends React.Component { window.navigator.userAgent.indexOf('Chrome') === -1 } + carbonNode = React.createRef() + updateState = updates => this.setState(updates, () => this.props.onUpdate(this.state)) updateCode = code => this.updateState({ code }) @@ -120,7 +120,7 @@ class Editor extends React.Component { return this.props.api.image(encodedState) } - const node = this.carbonNode + const node = this.carbonNode.current const map = new Map() const undoMap = value => { @@ -340,7 +340,7 @@ class Editor extends React.Component { onAspectRatioChange={this.updateAspectRatio} titleBar={titleBar} updateTitleBar={this.updateTitleBar} - innerRef={this.innerRef} + ref={this.carbonNode} > {code != null ? code : DEFAULT_CODE} diff --git a/pages/embed.js b/pages/embed.js index 23f83ad..fad1ff1 100644 --- a/pages/embed.js +++ b/pages/embed.js @@ -78,7 +78,7 @@ class Embed extends React.Component { // Used by embed provider src: window.location.toString(), context: 'iframe.resize', - height: this.ref.current.exportContainerNode.offsetHeight + height: this.ref.current.offsetHeight }), '*' )