【发布时间】:2021-08-01 11:02:34
【问题描述】:
我有一个 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;
【问题讨论】:
标签: reactjs react-native react-component konvajs konvajs-reactjs