update refs

This commit is contained in:
casper 2021-05-22 17:37:41 +02:00
parent 8e01a5c2e2
commit c472739baa

View File

@ -112,6 +112,8 @@ class Interface extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.canvasElement = React.createRef();
const scene = createScene(this.props); const scene = createScene(this.props);
this.state = { this.state = {
scene, scene,
@ -126,9 +128,8 @@ class Interface extends React.Component {
} }
componentDidMount() { componentDidMount() {
const { canvas } = this.refs;
const { scene } = this.state; const { scene } = this.state;
scene.updateCanvas(canvas); scene.updateCanvas(this.canvasElement.current);
const { mesh } = this.props; const { mesh } = this.props;
if (mesh) { if (mesh) {
@ -248,8 +249,7 @@ class Interface extends React.Component {
componentDidUpdate() { componentDidUpdate() {
const { scene: { updateCanvas } } = this.state; const { scene: { updateCanvas } } = this.state;
const { canvas } = this.refs; if (updateCanvas && this.canvasElement.current) updateCanvas(this.canvasElement.current);
if (updateCanvas && canvas) updateCanvas(canvas);
} }
onResize3dView = (width, height) => { onResize3dView = (width, height) => {
@ -325,7 +325,7 @@ class Interface extends React.Component {
const d3Panel = ( const d3Panel = (
<div className={classes.d3View}> <div className={classes.d3View}>
<ReactResizeDetector handleWidth handleHeight onResize={this.onResize3dView} /> <ReactResizeDetector handleWidth handleHeight onResize={this.onResize3dView} />
<canvas className={classes.canvas} ref="canvas" /> <canvas className={classes.canvas} ref={this.canvasElement} />
<div className={classes.controlBar}> <div className={classes.controlBar}>
<div className={classes.detail}> <div className={classes.detail}>
<p>Dimensions: {objectDimensions}</p> <p>Dimensions: {objectDimensions}</p>