Categories
React Answers

How to show HTML entities using React?

Spread the love

Sometimes, we want to show HTML entities using React.

In this article, we’ll look at how to show HTML entities using React.

How to show HTML entities using React?

To show HTML entities using React, we can wrap the HTML entity string with fragment.

For instance, we write:

import React from "react";

export default function App() {
  return (
    <div>
      2<>&sup3;</>
    </div>
  );
}

We wrap &sup3; in a fragment so that it’ll be rendered.

Therefore, we see 2³ displayed on the screen.

Conclusion

To show HTML entities using React, we can wrap the HTML entity string with fragment.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *