我有一个 KonvaJS 阶段的参考。在 ComponentDidMount 中,this.stageRef.current 的值为 null。任何想法为什么?
我的代码如下所示:
import React, { useState } from "react"
import { Stage, Layer, Rect, Text } from 'react-konva';
import Konva from 'konva';
class MyComponent extends React.Component {
constructor() {
super()
this.stageRef = React.createRef()
}
componentDidMount() {
// this.stageRef.current is null here!
}
render() {
return (
<>
<Stage id="canvas-text"
width={400} height={163}
className="stage"
ref={this.stageRef}>
<Layer>
<Text fontFamily='Karla' fontSize={24} align='center' width={400} y={30} text={"Hello"} />
</Layer>
</Stage>
</>
)
}
}
export default MyComponent;