react-in-patterns icon indicating copy to clipboard operation
react-in-patterns copied to clipboard

Using HTML Entities/Special Characters

Open pivanov opened this issue 8 years ago • 2 comments

Use String.fromCharCode() for special characters.

// bad
<div>John · Doe</div>

// nope
<div>John &middot; Doe</div>

// good
<div>{'John ' + String.fromCharCode(183) + ' Doe'}</div>

// better
<div>{`John ${String.fromCharCode(183)} Doe`}</div>

// Unicode
<i data-icon={String.fromCharCode(0xf00f)} />

// or if you have it as a string for some reason
<i data-icon={String.fromCharCode(parseInt('f00f', 16))} />

pivanov avatar Dec 06 '16 09:12 pivanov

Interesting. I'm preparing an article about anti-patterns so this will go there for sure. Thanks.

krasimir avatar Dec 06 '16 09:12 krasimir

thanks, great quickfix! Btw: String.fromCharCode is Vanilla, not React...

wende60 avatar Jul 17 '17 13:07 wende60