0

I had a problem using react-konva due to Dom element. When I tried to add a function to resize the screen of konva according to the size of the dom. I got this error thrown after adding layers.

const checkSize = contentRect => {
   const { width, height } = contentRect;
   stage.attrs({
     width,
     height
   });
   stage.batchDraw();
 };

export default class Review extends React.Component {
   constructor(props) {
    super(props);
     this.state = { stage: {} };
  }
  componentDidMount() {
    const { values, colorValue } = this.props;
     imageValue = values;
   colourValue = colorValue;
    this.state.stage = new Konva.Stage({
      container: "container",
      width: 0,
     height: 0
    });
    window.addEventListener("resize", checkSize);
  }

it throws an error at that stage

   layer = new Konva.Layer();
   stage.add(layer);

Error message: TypeError: stage is undefined

1 Answers1

0

I guess you need to take that variable from this.state as you saved it there:

const checkSize = contentRect => {
   const { width, height } = contentRect;
   this.state.stage.attrs({
     width,
     height
   });
   this.state.stage.batchDraw();
 };
lavrton
  • 18,973
  • 4
  • 30
  • 63