Correct way to define an empty dom element in React

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 = <label>My Label</label>; // react generates a label element
var label2 = null; // react doesn't generate any dom element
var label3 = ''; // react generates and empty span like <span></span>

Leave a Comment