2017-11-25 148 views
0

格式化我使用ReactJS教程hereReactJS在VS代碼

我用> code .開在VS代碼項目版本1.18。 後,我創建了一個文件index.js,然後添加代碼給出:

class Square extends React.Component { 
    render() { 
    return (
     <button className="square"> 
     {/* TODO */} 
     </button> 
    ); 
    } 
} 

當我按下Ctrl-S保存,VS代碼執行以下操作:

class Square extends React.Component { 
    render() { 
    return (document.render() < button className = "square" > { /* TODO */ } < 
    /button> 
    ); 
    } 
} 

注:更改到<button>。 所有的代碼被重新格式化。 我檢查了VS代碼的格式 - 它是錯誤的。 智能感知工作正常。 我還使用"jsx": "react"在我的src文件夾中添加了jsconfig.json。 VS代碼真的不可用,或者我錯過了什麼?

+0

https://stackoverflow.com/questions/45115112/how-to-prevent-insert-spaces-in-jsx-code –

回答

0

我不確定如何更改VSCode中的默認格式規則(您可能無法)。

我建議使用Prettier作爲代碼格式化程序。工作得非常好,並且可以讓您對代碼的格式設置有很多控制權。它也可以綁定到eslint。

請參閱this article on medium for instructions以獲取有關如何設置漂亮和eslint的說明。