How to show HTML entities using React?

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.