In this session we create a comment component to explore how to create components that only render text.
In previous versions of we had to wrap our text in needless <span>
or <div>
, we will see how React 16 removes the unneeded structure.
Here, you can see a common component rendering some text. The comment's purpose is to modify the text, mainly replacing text smileys with smile emojis. It currently contains a wrapping SPAN. Such wrapping elements were needed for components in React 15 or lower.
Let's explore a DOM structure. As you can see, our component is [inaudible 0:24] wrapped in a DIV, then once more in a SPAN. While the SPAN doesn't cause any problems, it also doesn't add any value, and the whole DOM would be cleaner and a bit more lightweight without it.
React 16 makes this possible. We can update our common component to return just plain text. Let's refresh the page, and as you can see, the comment will still be rendered. When we inspect the DOM, you can see the unnecessary SPAN is gone.