Render Text Only Components in React 16

Nik Graf
InstructorNik Graf
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 5 years ago

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.

Raja Sekar Durairaj
Raja Sekar Durairaj
~ 7 years ago

Actually keeping extra span will always trigger a fight between React and UI Developer. Hope this feature will helps me a lot

Raunaq Sahni
Raunaq Sahni
~ 5 years ago

For some reason, I'm having trouble playing this particular video on the web and after download; tried multiple browsers as well as media softwares.

Markdown supported.
Become a member to join the discussionEnroll Today