问题
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