search

Home  >  Q&A  >  body text

Problems React encounters when using utf-8

<p>I am developing a React based solution using Visual Studio. My React .js files are encoded in UTF-8. </p> <p>I'm using some Danish text and what confuses me is that I have to rewrite ø as &oslash;</p> <p>The reason I'm confused is because the browser displays UTF-8 replacement characters, so I assume it must be using UTF-8 encoding all the time. </p> <p>Am I overlooking something obvious? </p> <p>Here is a code that demonstrates the problem: </p> <pre class="brush:php;toolbar:false;">render() { return ( <div> Sogning. S&oslash;gning. </div> ); }</pre>
P粉644981029P粉644981029508 days ago650

reply all(1)I'll reply

  • P粉755863750

    P粉7558637502023-08-17 09:07:07

    You can use the following ways to represent them in js files:

    import utf8 from "utf8";
    
    const encoded = utf8.encode(Søgning)

    If you use this in a .jsx file, there is no need to encode special characters. You can use it like this in a .jsx file:

    render() {
        return (
            <div>
                Søgning.
                Søgning.
            </div>
        );
    }

    reply
    0
  • Cancelreply