Used the reactjs in vscode was report an error

青春壹個敷衍的年華 提交于 2021-02-17 06:23:06

问题


use "jsx" grammar in visual studio code. visual studio code report an error

Please help me. Thanks!!!


回答1:


The symbol "<" should appear in the same line with the tag name.

For example, instead of doing that:

   return (     <
      button className="square"> {/*TODO*/} <
      /button>
   )

Do that:

  return(
    <button className="square"> 
         {/*TODO*/}
    </button>
)

If you want to split the tag to multiple lines, you can do it like that:

      return (
        <button 
          className="square"
          id="id"
          onClick={someFunc}
        > 
             {/*TODO*/}
        </button>
       )



回答2:


There is a button in the lower-right side of the VScode window (yours says "Javascript Standard Style"). If you click that you can select a different language mode. You want to select the one that works with React. You may also be able to select "Auto-detect" from the menu list.

For example, mine says "Javascript React"

The language mode can also be selected from the command-palette (CMD-Shift-p on Mac, not sure what it it is on other OS's, but you can also reach it from toolbar > View)..



来源:https://stackoverflow.com/questions/65758184/used-the-reactjs-in-vscode-was-report-an-error

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