add this in your .js code,
/* prettier-ignore */
Not allowed to post a picture yet, but this is the extensions I use.
The first one is called
Beautify - helps with HTML, CSS, JS
The second one is
rc-beautify - helps with TS, JS, React.
Here is what worked for me-
That pretty much did it for me after I saved the React file.
You can install an extension like react-beautify that helps you format your jsx code.
It is found here
I had similar problem, then I found out it was caused by 'beautify' extension. After I uninstalled the extension, everything is working fine.
I had to disable the JS-CSS-HTML Formatter extension in VSC. only solution to this problem
After reading many great suggestions and workarounds, I discovered that I could simply place my mouse arrow down over the bright blue horizontal bar at the bottom of VSCode editor window - right click - which opens a popup list window - and deselected = "Editor Indentation".
You can double click
React in the Select language mode to associate with
I just added all the combinations mentioned above.
- added this
- added this also
- Deleted additional js formatting
- installed prettier
- turn ON prettier and formatting
react-beautify mostly does the magic but fails if you have some other JS formatter/beautifier already installed.
In my case, I had react-beautify and JS-CSS-HTML Formatter extension installed. I had to disable the JS-CSS-HTML Formatter for my current workspace.
Install Prettier (if not installed by default) and try to add this to your user or workplace settings:
Do not put linebreak between return and the returned JSX expression.
(Alt+Shift+F) and check if works.
I struggled with this but finally found a solution. This is my settings.json
Open the Visual Studio Code Settings. Refer the image below to see how to navigate to the settings.
Once the settings tab is open. If you want to make the settings changes for all the projects then select the User sub tab, if only for current project then select the Workspace sub tab.
type "file associations" in the search text box and press Enter.
Click on add item.
- set Item : *.js
Above changes will start associating all
Next open any
.js file in your project and right click and select Format Document. If you have multiple formatters then associate your favorite formatter. I have used Prettier to handle my formatting.
Alternatively, saving the file with a .jsx extension resolves this in vscode.
I had the same challenge and I am hoping to discover a better way of handling this issue in vscode.
I noticed your suggested work-around has to be done each time you open the react file with an extension of .js
You can prevent VSC from incorrectly formatting your JSX by adding an association in your settings.json
In the settings window search for associations, click edit in settings.json and then add:
change vscode preferences settings > user settings below:
- Visual studio code changes format (React-JSX)
- JSX or HTML autocompletion in Visual Studio Code
- Change language to JSX in Visual Studio Code
- Auto Import of React Components in Visual Studio Code
- React intellisense in Visual Studio Code
- Setting up proper React Code highlighting in Visual Studio Code?
- Breakpoints not working debugging React app in Chrome through Visual Studio Code on Windows 10 and WSL2
- How to get Visual Studio Code to navigate to a React component's source file?
- Visual Studio code error while saving react files?
- Visual Studio Code React not showing error even after adding jsconfig
- Visual Studio Code unbound breakpoint Node JS React TypeScript
- In Visual Studio 2012, I get warnings and squiggly lines when trying to write JSX with React JS
- Visual Studio Code doesn't autocomplete JSX attributes
- How to set up jsx syntax highlight and Intellisense in Visual Studio Code 1.5.2?
- Babel cannot compile simple JSX for React's render() function - Using Visual Studio Code
- Visual Studio Code Chrome Debugger doesn't set breakpoints inside generator function in React
- Visual Studio Code is not npm start-ing my React JS app when debugging
- React TypeScript type hint auto-completion does not work with React.forwardRef in Visual Studio Code
- Visual Studio React Typescript webpack-dev-server hot reload not working for component changes
- How to format React Codes in Visual Studio Code?
- Visual Studio Code functional snippet React
- Am I missing some code to view this video in a react app using visual studio code [react]
- Visual Studio Code / React - Is there a possibility to display all possible props somewhere?
- Formatting code with <pre> tag in React and JSX
- React project in Visual Studio 2017
- "Failed to load resource: net::ERR_HTTP2_PROTOCOL_ERROR" for React app after upgrading to Visual Studio 2019 16.10.0
- Auto Import in Visual Studio Code for React-Native Development
- Visual Studio Code [eslint] Delete 'CR' [prettier/prettier] on windows
- Visual Studio Code autocomplete when I press "." key. Any way to disable?
- How to debug react native apps in visual studio code?
More Query from same tag
- React debug in browser when using bundle.js
- Is there a way to render color using the interweave library in React?
- React-router 4 -- NavLink with shared component not updating
- Access to the parent key prop for all childrens events
- React: Reload logic on route change
- Script with jsx and script without jsx not working on the same page
- ReactJS: Filter rendering of a list by whole names only?
- React root.js weights about 9MB
- Removing an item from an array of items only removes the last item
- Rename the URL'name in React Router Breadcrumb component
- react render doesn't show anything
- Express/mssql login form throws "ReferenceError:"" is not defined"
- remove whitespace between image and container
- Page transition using react-router and react-addons-css-transition-group
- What does withRouter and props in routes?
- What is sunproxyadmin service?
- I can't Change text in the form in React
- Passing an object from React to Express and creating a new Airtable record
- menuItem conditional rendering of item with boolean value
- How do you animate menu with framer motion on-click?
- How do I make an undefined item in an object's length equal to 0 in reactjs?
- reload component - React
- HMR for create-react-app with react-redux
- TypeError: util__WEBPACK_IMPORTED_MODULE_4___default(...) is not a function
- How to use repeat and minmax in tailwind
- How to rerender a React component which gets API data?
- How do I use React classes now in Ruby on Rails with WebPack
- Django ReactJS web app Icons and Images Inside Public Folder Not Showing
- Typeerror : failed to fetch while Uploading file in SharePoint using pnpjs