I'm new to Visual Studio Code and trying to get emmet to work on JSX. I read that I had to use the following code in my settings, but it is still not working. Can anyone troubleshoot for me?
"emmet.includeLanguages": {
"html": "html",
"javascript": "javascriptreact",
"xml": {
"attr_quotes": "single"
}
},
"emmet.triggerExpansionOnTab": true
}
Go to settings > extensions > emmet > include languages and add javascript as the item and javascriptreact as the value.
Emmet does not work in js/jsx files for VS Code 1.62.
Emmets don't work in JS files. However, you can set it so that VS Code thinks that it's a JSX file and it would give React IntelliSense.
Easy way to enable emmet for React It's already included for all HTML and CSS files by default in VS code but we need to do some extra configuration to enable it for React. 4. Once opened, add "javascript": "javascriptreact" under “ emmet. includeLanguages ” and save the file.
In VSCode, Emmet is built-in, so it works out of the box when you want to do autocompletion inside your .html files. But when you’re inside a React file, this autocompletion doesn’t always work. In that case, you’ll have to enable Emmet’s triggerExpansionOnTab function manually inside your project’s Workspace Settings.
this is the recommended way to do it, we do not want to enable emmet by default in JS. Then you are missing features like jump to symbol etc that you get with "Javascript". this should not be the case, since the same language service/parser is used for .js and .jsx files.
@admmasters Emmet expansions are working fine in .tsx files. For it to work in .ts files you need to either map "typescript" to "jsx" in emmet.syntaxProfiles or change language mode to tyspescriptreact Sorry, something went wrong.
For example, typing h1 followed by hitting the TAB key (on your keyboard) will automatically create a complete h1 element (open/close tags) <h1></h1> and thus save you a lot of typing. In VSCode, Emmet is built-in, so it works out of the box when you want to do autocompletion inside your .html files.
This works for me:
"emmet.includeLanguages": {
"html": "html",
"javascript": "javascriptreact",
"xml": {
"attr_quotes": "single"
}
},
"emmet.triggerExpansionOnTab": true
The only difference to your code is I removed the last curly brace so it is properly contained within the settings.json
object. If you want these settings to work with all your files and projects make sure the changes are in your USER SETTINGS
.
Here is the VSCode related documentation for Emmet configuration.
i found out that sometimes Emmet "forgets" to look for HTML in JS files, but it still does work in JSX and CSS files. So I put a few lines to "remind" Emmet look HTML in js files as well, associate with them, here it is:
"emmet.triggerExpansionOnTab": true,
"emmet.includeLanguages": {
"javascript": "javascriptreact"
}
or this:
"emmet.triggerExpansionOnTab": true,
"files.associations": { "*.js": "javascriptreact" }
here is the source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With