在TSX文件中:属性'createRef'在类型'typeof React'上不存在

Ama*_*mar 6 javascript jsx typescript reactjs tsx

我需要组件的引用.刚刚从jsx转移到tsx,无法找到解决此问题的方法.

其他解决方法是使用查询选择器,但这并不是我认为做出反应的好方法.

这是构造函数

constructor(props) {
    super(props);
    this.state = {
        data: initialData,
        showNewListForm: false,
        whichButtonClicked: undefined,
        background: props.background || "#23719f"
    };

    this.divContainerRef = React.createRef();
    console.log("kanban reference : " + React.createRef().current);

    this.handleDragStart = this.handleDragStart.bind(this);
    this.handleDragEnd = this.handleDragEnd.bind(this);
    this.handleLaneDragEnd = this.handleLaneDragEnd.bind(this);
    this.handleLaneDragStart = this.handleLaneDragStart.bind(this);
    this.onCardAdd = this.onCardAdd.bind(this);
    this.onCardClick = this.onCardClick.bind(this);
    this.addNewListHandler = this.addNewListHandler.bind(this);
    this.containerRefResolver = this.containerRefResolver.bind(this);
    this.isBoardPresent = this.isBoardPresent.bind(this);
}
Run Code Online (Sandbox Code Playgroud)

Way*_*neC 12

看起来你有一个过时的版本@types/react.最新版本16.3.14具有类型定义createRef.