Want to show html entity using React? You can get that using dangerouslySetInnerHTML feature of jsx. Another way would be use correspond unicode character of html entity and just use as normal string.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
const formatArea = function(val){ return val + " ft³"; } const Comp = ({text}) => ( <div> <div dangerouslySetInnerHTML={{__html: `${text}`}} /> <div>{'53 ft\u00B3'}</div> </div> ); ReactDOM.render( <Comp text={formatArea(53)} /> , document.getElementById('root') ); |
1 2 3 4 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script> <div id="root"></div> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.