How to render accents in ReactJs?

后端 未结 3 1400
陌清茗
陌清茗 2020-12-20 23:27

I\'m trying render an element which has an accent character using ReactJS and JSX, but it\'s not returning what I wanted.

My JSX:

var Or         


        
相关标签:
3条回答
  • 2020-12-21 00:14

    I resolved! the problem is because I'm compiling JSX using gulp, and file generated is not UTF-8, so I save as file in UTF-8 that is working!

    0 讨论(0)
  • 2020-12-21 00:23

    What you see, Orçamento, it's a result of a UTF-8 byte array being rendered in ASCII, probably codepage ISO 8859-1.

    ReactJS doesn't support non-ASCII characters within HTML.

    Try this:

    var Orcamento = React.createClass({
        render: function() {
            return (
                <div>
                    <h1> { 'Orçamento' } </h1>
    
                </div>;
            );
        }
    });
    

    Or simply replace orçamento by Or&#231;amento.

    This is well explained in the JSX gotchas.

    0 讨论(0)
  • 2020-12-21 00:25

    Also using the charset utf-8, try using this library: https://github.com/mathiasbynens/he

    import { decode } from 'he';
    
    class Post extends Component { 
      render() {
        <h1>{ decode(this.props.post.title) }</h1>  
      }
    }   
    
    0 讨论(0)
提交回复
热议问题