How to add a copyright symbol in reason-react component?

喜夏-厌秋 提交于 2020-01-03 16:45:01

问题


I’m new to reason-react. I’m trying to put a copyright symbol in a react-reason component. I've tried

<span >(ReasonReact.stringToElement("&copy;"))</span>

but this doesn’t give me the © symbol.


回答1:


It's also possible, and usually simpler, to just use the unicode character:

let copy = ReasonReact.stringToElement({js|\u00a9|js});

// Since ReasonReact 0.7.0 you can use
let copy = React.string({js|\u00a9|js});

Or even shorter:

let copy = [%raw {|'\u00a9'|}];

It's also possible to use unicode characters directly, as long as the whole toolchain supports it properly:

let copy = React.string({js|©|js});

Then for either of these you can now do:

<span> {copy} </span>



回答2:


If you're doing HTML entities like that you have to use the dangerouslySetInnerHTML attribute like so:

<span dangerouslySetInnerHTML={{ "__html": "&copy;" }} />


来源:https://stackoverflow.com/questions/49039433/how-to-add-a-copyright-symbol-in-reason-react-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!