skip to Main Content

screenshot of the issue

Can someone tell me why, thank you

Is it because one is a text node and another is a variable

2

Answers


  1. Those special characters don’t work in HTML, the literal text ‘rn’ will be rendered in the browser.

    Using the backtick ` character creates a Template String, which has a bit more ‘syntactic sugar’ and functionality than raw HTML text. It is a Javascript string and you can use JS special characters (e.g. rn) inside it.

    HTML uses character encodings instead, which look like this: 
. This represents the n ‘newline’ character, and will work in your example.

    Login or Signup to reply.
  2. <div>123rn123</div>
    

    The former one is pure HTML, i.e. what is between the opening and closing tags will be displayed as is.

    <div>{'123rn123'}</div>
    

    Whereas the latter one is JSX, where the inner content is a string (programmatically speaking) – notice the use of {} in the tags – thus r and n being escape characters

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search