I have a component with a data-icon
attribute. The value of this attribute should be, for instance, 
so that css can render it via content: attr( data-icon );
.
However, whatever I try: React keeps escaping to &
. Even when I provide the proper unicode character \u0026#xf00f
.
Is there some way to stop React from messing with that value? Besides dangerously setting inner html, as I do not want to add another wrapper.
Component
define( [ 'react', 'util' ], function( React, Util )
{
return React.createClass(
{
render: function()
{
//var amp = '\u0026',
var amp = String.fromCharCode( 38 ),
// Util.icons[x] returns a String, such as "f00f"
code = amp + '#x' + Util.icons[this.props.name] + ';';
return (
<i data-icon={code}>
{this.props.children ? <span>{this.props.children}</span> : null}
</i>
);
}
} );
} );
Usage
<Widget.Icon name="add" />
Output
<i data-icon="&#xf0fb;" data-reactid=".170lse36465.7.0"></i>
I have a component with a data-icon
attribute. The value of this attribute should be, for instance, 
so that css can render it via content: attr( data-icon );
.
However, whatever I try: React keeps escaping to &
. Even when I provide the proper unicode character \u0026#xf00f
.
Is there some way to stop React from messing with that value? Besides dangerously setting inner html, as I do not want to add another wrapper.
Component
define( [ 'react', 'util' ], function( React, Util )
{
return React.createClass(
{
render: function()
{
//var amp = '\u0026',
var amp = String.fromCharCode( 38 ),
// Util.icons[x] returns a String, such as "f00f"
code = amp + '#x' + Util.icons[this.props.name] + ';';
return (
<i data-icon={code}>
{this.props.children ? <span>{this.props.children}</span> : null}
</i>
);
}
} );
} );
Usage
<Widget.Icon name="add" />
Output
<i data-icon="&#xf0fb;" data-reactid=".170lse36465.7.0"></i>
Share
Improve this question
edited Apr 28, 2015 at 12:29
Taig
asked Apr 27, 2015 at 22:32
TaigTaig
7,2884 gold badges47 silver badges67 bronze badges
6
|
Show 1 more comment
1 Answer
Reset to default 17Well, I just realized, that for my particular use case I can simply get away with:
<i data-icon={String.fromCharCode( "f00f" )} />
https://github.com/facebook/react/issues/3769
&
is displayed as&
), but you can see that the css struggles (It should display an invalid character). With serverside rendering in my app I can see the undesired&
output in the html source. – Taig Commented Apr 28, 2015 at 13:09