Correct way to define an empty dom element in React

后端 未结 2 703
花落未央
花落未央 2021-02-05 00:19

I send an optional parameter checkbox inside a prop to a component:

var checkBox = this.props.checkbox ?          


        
2条回答
  •  逝去的感伤
    2021-02-05 01:06

    You need to use null. If you use an empty string like '' then react will create an empty span dom element, so it's not the same.

    var label1 = ; // react generates a label element
    var label2 = null; // react doesn't generate any dom element
    var label3 = ''; // react generates and empty span like 
    

提交回复
热议问题