Type 'null' is not assignable to type 'HTMLInputElement' ReactJs

后端 未结 3 1540
粉色の甜心
粉色の甜心 2021-02-19 01:28

I am trying to reference data into reactJS along with typescript. While doing this I am getting below error

Type \'null\' is not assignable to type \'HTMLInputEl         


        
3条回答
  •  被撕碎了的回忆
    2021-02-19 01:54

    I solved in react using if condition before i use ref

      if (this.ref.current) {
    
          this.editor = monaco.editor.create(
              this.ref.current,
              { automaticLayout: true }
          );
    
          monaco.editor.setTheme('vs-dark');
          this.editor.setModel(this.model);
      }
    

提交回复
热议问题