How to use refs in React with Typescript

前端 未结 15 1455
闹比i
闹比i 2020-11-28 05:03

I\'m using Typescript with React. I\'m having trouble understanding how to use refs so as to get static typing and intellisense with respect to the react nodes referenced by

15条回答
  •  借酒劲吻你
    2020-11-28 05:33

    For typescript user no constructor required.

    ...

    private divRef: HTMLDivElement | null = null
    
    getDivRef = (ref: HTMLDivElement | null): void => {
        this.divRef = ref
    }
    
    render() {
        return 
    }

    ...

提交回复
热议问题