How to convert pokémon to accent e

35 Views Asked by At

I'm receiving string from the back-end which is pokémon but it should be pokémon this is why I'm trying to find a way to convert é in the string to é but couldn't find any solution for that

  • My meta tag is utf-8
  • Tried normalizer
1

There are 1 best solutions below

3
Keith On

You could just use the browsers built in DOM parser. Basically set the innerHTML of a DOM element, and then read with the innerText. Your then free to use this string inside your React control.

eg.

const d = document.createElement('div');

d.innerHTML = 'pokémon';

console.log(d.innerText);

To make the above code more re-usable you could do ->

const normalizeText = (() => {
  const d = document.createElement('div');
  return t => {
    d.innerHTML = t;
    return d.innerText;
  }
})();


console.log(normalizeText('pokémon'));