1- import React , { useState , useEffect , useRef } from 'react' ;
1+ import React , { useState , useEffect , useRef , useCallback , useLayoutEffect } from 'react' ;
22import { samples } from '@python36/scene-xml' ;
33
44import { sceneProcessors } from './processors' ;
@@ -13,7 +13,7 @@ const App: React.FC = () => {
1313 const renderingEl = useRef ( null ) ;
1414
1515 const setScene = ( e : any ) => setXmlInput ( samples [ e . target . value ] ) ;
16- const setHeight = ( ) :void => {
16+ const setHeight = useCallback ( ( ) :void => {
1717 console . log ( 'setHeight():' , { renderingEl} )
1818 if ( renderingEl && renderingEl . current ) {
1919 const elm = renderingEl . current as any ;
@@ -22,7 +22,7 @@ const App: React.FC = () => {
2222 setTextareaHeight ( elm . clientHeight ) ;
2323 }
2424 }
25- } ;
25+ } , [ renderingEl , textareaHeight ] ) ;
2626
2727 const render = ( ) => {
2828 const selectedProcessor = sceneProcessors [ processor ] ;
@@ -45,15 +45,16 @@ const App: React.FC = () => {
4545 return ( ) => window . removeEventListener ( 'resize' , setHeight ) ;
4646 } , [ setHeight ] ) ;
4747
48- useEffect ( ( ) => void setTimeout ( setHeight , 1000 ) ) ;
49-
48+ useLayoutEffect ( ( ) => void setTimeout ( ( ) =>
49+ window . dispatchEvent ( new Event ( 'resize' ) ) , 1 )
50+ , [ imageURL ] ) ;
51+
5052 return (
5153 < div className = "container" >
5254 < hr />
5355
5456 < div className = "row" >
5557 < div className = "col-md-6" >
56- { /* {imageURL && (<img src={imageURL} ref={renderingEl} className="rendering" />) } */ }
5758 < img src = { imageURL } ref = { renderingEl } className = "rendering" />
5859 </ div >
5960 < div className = "col-md-6 visible-md-inline visible-lg-inline" >
0 commit comments