The main premise is that JSX compiler parses HTML entities, but React does NOT. This inconsistent behavior is easy source of bugs. When you pass plain string as prop with value ©, it works as expected, ie. html char of copyright symbol is present. The JSX compiler parses that as expected. BUT value of {'&' + 'copy' + ';'} will result in plain string ©. As precaution I always use String.fromCharCode so I don't have to think if React parses it or it's on JSX compiler.
©
{'&' + 'copy' + ';'}
String.fromCharCode
const copySymbol = '©'; <Button symbol={copySymbol} /> // results in '©' <Button symbol={'&' + 'copy' + ';'} /> // results in '©' <Button symbol="©" /> // results in '©' <Button symbol={String.fromCharCode(169)} /> // results in '©' const copySymbolFromCharCode = String.fromCharCode(169) <Button symbol={copySymbolFromCharCode} /> // results in '©'
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The main premise is that JSX compiler parses HTML entities, but React does NOT. This inconsistent behavior is easy source of bugs. When you pass plain string as prop with value
©
, it works as expected, ie. html char of copyright symbol is present. The JSX compiler parses that as expected. BUT value of{'&' + 'copy' + ';'}
will result in plain string©
. As precaution I always useString.fromCharCode
so I don't have to think if React parses it or it's on JSX compiler.