12 Days of Baddass Courses sale! Get instant access to the entire egghead library of courses and lessons for 58% off.

Runs out in:
05 : 09 : 32 : 58
Join egghead, unlock knowledge.

Want more egghead? It's 58% off for a limited time only!

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock All Content for 40% Off
Become a member
to unlock all features

    Render Text Only Components in React 16

    Nik GrafNik Graf

    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.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




    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.