Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using HTML Entities/Special Characters #17

Open
pivanov opened this issue Dec 6, 2016 · 2 comments
Open

Using HTML Entities/Special Characters #17

pivanov opened this issue Dec 6, 2016 · 2 comments

Comments

@pivanov
Copy link

pivanov commented Dec 6, 2016

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))} />
@krasimir
Copy link
Owner

krasimir commented Dec 6, 2016

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

@wende60
Copy link

wende60 commented Jul 17, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants