How to fix this violation of this 'react/no-unescaped-entitie' of eslint rule?

Anthony Kong picture Anthony Kong · Apr 3, 2017 · Viewed 24.8k times · Source

This is my code:

const func = () => {
  return (
    <div >
       you're free
      </div>
  )}

Somehow eslint flags the line "you're free" with error error HTML entities must be escaped react/no-unescaped-entities

However from what I can see jsx has escaped the apostrophes already. I can see the words you're free is rendered without issue. If I escape it as &#39;, then it will be very hard for me to search for the string (I would expect a search of you're free in an editor to return a hit. But obviously the editor will miss because the text is actually you&#39;re free)

So what is the best way to address this eslint exception?

Answer

Noitidart picture Noitidart · Aug 26, 2017

Recommended solution is to use &apos;, &lsquo; or &rsquo; instead of wrapping it as a variable. So like this:

const func = () => {
  return (
    <div >
       you&apos;re free
      </div>
  )}

For search-ability, it's recommended you have files for localization/internationalization and call them into your app.