Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In TSX file : Property 'createRef' does not exist on type 'typeof React'

I need the reference of the component. Just shifted from jsx to tsx and can't find a solution for this problem.

Other workaround would be to use query selector but that's not a good way of doing things in react I believe.

Here is the constructor function

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);
}
like image 976
Aman Kumar Avatar asked May 15 '18 10:05

Aman Kumar


2 Answers

Looks like you have an out of date version of @types/react. The latest version 16.3.14 has type definitions for createRef.

like image 154
WayneC Avatar answered Nov 18 '22 12:11

WayneC


In my Typescript codebase I had to update react-dom types:

yarn upgrade @types/react-dom^16.3.0

like image 33
Damian Green Avatar answered Nov 18 '22 11:11

Damian Green