I'm coding out a temperature app with React and I'm on the part where I'm displaying the different temperatures within the element.
Now I'm trying to do °F
to return Fahrenheit, but then it occurred to me: this is JSX
, not HTML. Sure enough, when you put this into a component, it returns an error because the DOM is trying to read JavaScript.
Is there a good workaround for this?
You can use HTML entities within literal text in JSX.
function App() {
return <h1>°F</h1>;
}
You can use the unicode number corresponding to the entity if you need it inside a string.
function App() {
return <h1>{'\u00b0'}</h1>;
}
A few other ways of approaching it are listed in the JSX Gotchas part of the documentation.
Usually I just type the actual symbol. In your case: ºF
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With