How can I render UTF-8 characters in JSX without using dangerouslySetInnerHTML in 2020

拜拜、爱过 提交于 2021-01-29 18:53:02

问题


For context, I have a form in my ReactJS app and I submit:

Awp ACq smr`Q pRBu deI bfweI nwm [

My API ends up saving that value in the database as the following value:

Awp ACq smr`Q pRBu deI bfweI nwm [

However, when I go to display this in the my React app, it renders the following:

This is what (I think) it should be:

How can I correctly display this content in React? It feels like I am doing something wrong by the lack of sources I could find:

  • React Javascript displaying/decoding unicode characters (2016)
  • https://www.jsdiaries.com/how-to-add-unicode-in-react-js/ (2020)

Here are some additional question I want to clarify:

  • When I submit strings (with extended ASCII, special characters) is it normal for the special characters to be encoded? For example, why was converting the ` to ` necessary?
  • What is the difference between the Unicode and HTML "representation" of that character? Why did the server decide to use ` instead of U+0060? Which one is more preferable to use to serve to more devices?

来源:https://stackoverflow.com/questions/64073935/how-can-i-render-utf-8-characters-in-jsx-without-using-dangerouslysetinnerhtml-i

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