如何使用React显示HTML实体? [英] How to show html entity using React?
本文介绍了如何使用React显示HTML实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想显示立方" html实体(上标3).我在做这个:
I am wanting to show the 'cubic' html entity (superscript 3). I am doing like this:
const formatArea = function(val){
return val + " ft³";
}
其中 formatArea
是从组件内部调用的:
where formatArea
is being called from inside the component':
render(){
return (
<div>
{formatArea(this.props.area)}
</div>
);
}
但是,浏览器将其显示为 ft& sup3;
but, the browser is showing it as ft³
推荐答案
使用JSX通过以下方式发现:
Found this way using JSX:
const formatArea = (val) => {
return (<span>{val} ft<sup>3</sup></span>);
}
这篇关于如何使用React显示HTML实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文