I am working on a react app and stuck over how to display apostrophe in jsx. I have some text which should come with apostrophe but its coming with code.
What I need is : This is ashwani`s app
How its coming is : This is ashwani's app'
What I am using is : tittle = 'This is ashwani's app'
I also tried : 'This is ashwani${'''}s app'
But nothing is working.
CodePudding user response:
If you're getting the title (from API , database ....) like this This is ashwani's app
and you want it to be like this This is ashwani
s app` you can simply use .replace method
example :
const title = "This is ashwani's app".replace("'", "'");
CodePudding user response:
This is a generic solution that handles all these HTML entities without having to statically create a map in order to reference each entity every time.
const p = "This is ashwani's app'";
console.log(p.replace(/&([a-z]{1,4});/gi, match => new DOMParser().parseFromString(match, "text/html").documentElement.textContent));