When I save or format my React code with Ctrl Shift F the code below, is formatted in a strange way.
How can I solve this?
Default code:
import logo from './logo.svg';
import './App.css';
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Hello CodeCademy
</a>
</header>
</div>
);
}
export default App;
After formatting the code:
import logo from './logo.svg';
import './App.css';
function App() {
return ( <
div className = "App" >
<
header className = "App-header" >
<
img src = { logo }
className = "App-logo"
alt = "logo" / >
<
p >
Edit < code > src / App.js < /code> and save to reload. <
/p> <
a className = "App-link"
href = "https://reactjs.org"
target = "_blank"
rel = "noopener noreferrer" >
Hello CodeCademy <
/a> <
/header> <
/div>
);
}
export default App;
I tried to install another formatter and go to my settings to remove my "html" "twig" extension in emmet.
CodePudding user response:
Follow these steps:
CTRL SHIFT P
- Format Document (in pop-up bar)
- Select
Format Document
- Select
Configure Default Formatter...
- Select
Prettier - Code formatter
To enable Format On Save
CTRL SHIFT P
- Preferences Open Settings (UI) (in pop-up bar)
- Type
Format On Save
- Enable
Format On Save
if it is not checked
Done!
CodePudding user response:
Download the Prettier extension for VSCode. Follow this article.
CodePudding user response:
I have had the same issue, even thus I have installed the Prettier extension. It shows later that I have had another extension called JS-CSS-HTML Formatter. I uninstalled JS-CSS-HTML Formatter and kept Prettier, and all problem was solved.
This issue is mentioned here as well.