Formatting code with
 tag in React and JSX

前端 未结 5 790
暖寄归人
暖寄归人 2020-12-13 04:07

I am trying to use the pre tag inside of JSX.When you use the pre tag in JSX, it doesn\'t format at all. Why? In order to use the pre tag I need to do something like this:

5条回答
  •  余生分开走
    2020-12-13 04:49

    Use template literals

    Template literals allow the use of multi-line strings which preserve leading/trailing white-space and new lines.

    class SomeComponent extends React.Component {
       render() {
            return (
              
    {`
                Hello   ,   
                World   .
              `}
    ) } }

    class SomeComponent extends React.Component {
       render() {
            return (
              
    {`
                Hello   ,   
                World   .
              `}
    ) } } ReactDOM.render( , document.getElementById('pre') )
    
    
    
    
    
                Hello   ,
                World   .
    

提交回复
热议问题