Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

ESLint react/no-unescaped-entities on an apostrophe or quote in JSX

Errorreact/no-unescaped-entities

Short answer

The rule react/no-unescaped-entities forbids four characters in JSX text: > " ' and }. Replace each with its entity (' " > }) or write the text as a JavaScript string inside braces. If your team wants fewer characters blocked, set the forbid option instead of turning the rule off.

  • Applies to eslint-plugin-react 7
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run ESLint on the file. The report gives the line and the character that triggered the rule.

    npx eslint src/pages/About.jsx
  2. 2Match what you see, then jump to its fix

    1. 1react/no-unescaped-entities on text such as <p>Don't stop</p>A raw apostrophe or double quote in JSX textFix
    2. 2The same rule on text like <p>a > b</p> or code samples with closing bracesA raw > or } in JSX textFix
    3. 3Hundreds of reports for apostrophes in long copyThe default list is stricter than your team wantsFix

What does the error look like?

  • react/no-unescaped-entities

Cause 1 of 3

A raw apostrophe or double quote in JSX text

1Check

Look at the reported line. The character sits in text between tags, not in an attribute or an expression.

grep -rn "<p>[^<]*'" src/

2Fix

Use an HTML entity, or put the string in a JavaScript expression. Both render the same character.

<p>Don&apos;t stop</p>
<p>She said &quot;yes&quot;</p>
<p>{"Don't stop"}</p>

3Verify

ESLint reports nothing for the line and the page shows the apostrophe.

npx eslint src/pages/About.jsx

Confirmed by github.com

Did this fix it?

Cause 2 of 3

A raw > or } in JSX text

1Check

The rule also forbids > and }. It does not check < or {, because those are already syntax errors inside a tag.

grep -rn '<p>[^<]*[>}]' src/

2Fix

Use &gt; and &#125;, or a string in braces.

<p>a &gt; b</p>
<code>{'}'}</code>

3Verify

Run ESLint again.

npx eslint src/

Confirmed by github.com

Did this fix it?

Cause 3 of 3

The default list is stricter than your team wants

1Check

The forbid option replaces the default character list. Without it, all four characters are checked.

grep -n 'no-unescaped-entities' .eslintrc* eslint.config.*

2Fix

List only the characters you still want blocked.

"react/no-unescaped-entities": ["error", { "forbid": [">", "}"] }]

3Verify

ESLint passes on the apostrophes, and still flags > and }.

npx eslint src/

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Write text with a typographic apostrophe (the right single quote) in content files, or keep copy in strings.
  • Run ESLint in the editor so the report appears while you type.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.