Convert Unicode characters

Hi there,

I am currently working on the random quote project and I am fetching data from this API[orderby]=rand&filter[posts_per_page]=1

It appears that sometimes I get unicode characters like ’ for " ’ ". Is there a function or a way I could parse my whole quote to remove enventual unicode characters ?

I am fetching through Axios with React.



Look what I found (quite clever solution):

1 Like

Thanks ! It seems weird but it does work :smiley:

Its caused by JSX double escaping the string. It’s escaped anyway as a security precaution, but what you have from the API is already escaped. See:

You can write a function to parse the string before you render it and replace any entities. This is the safest option, but the issue you’ll have is you might not know in advance if there are other entities that need decoding that aren’t just quotes. dangerouslySetInnerHTML is probably the best bet in this case (but note the name, it’s there as a warning), as it won’t escape the string, so it should render as you want it to with the quote marks.