Why Flow cannot call ReactDOM.render with document.getElementById(…)

前端 未结 2 1534

I was getting this error below in Flow type checking.

Cannot call ReactDOM.render with document.getElementById(...) bound to container because null [1] is
incomp         


        
2条回答
  •  死守一世寂寞
    2021-02-19 06:23

    While Cogell's answer is correct, I would argue to keep the code simpler and add an exception.

    ReactDOM.render(
     
      
        
          
            
            
            
            
          
        
      
     , // $FlowIgnore
     document.getElementById("root")
    );
    

    Notice the "$FlowIgnore" comment

    and then in your .flowconfig file add this to the "options" field:

    suppress_comment= \\(.\\|\n\\)*\\$FlowIgnore

提交回复
热议问题