score:150
visual studio code detect .jsx extensions and add emmet support by default ( i'm using vs code 1.8.1)
but if you prefer to use .js extention for all your react files - you can associate javascript react mode with .js files in bottom right corner of vs code window.
how to do this step by step (gif)
update 2021
for those who just want to copy-paste the code:
"emmet.syntaxprofiles": {
"javascript": "jsx"
}
if the solution above doesn't work, try this:
"emmet.triggerexpansionontab": true,
"emmet.includelanguages": {
"javascript": "javascriptreact"
}
tested with vs code v1.56.2.
score:0
just name the file you are working on from .js
to .jsx
and you are fine .
score:1
autocomplete for react babel was working fine until yesterday for me.
none of these answers helped so i just restarted my computer. worked like a charm ;)
score:1
i was working on various projects and i have a big settings file.
i checked settings and found out that this settings was ruining that all.
"emmet.showexpandedabbreviation": "inmarkupandstylesheetfilesonly"
so i commented it. and everyhting works perfectly in react apps. thanks
score:1
only work in jsx files. let it not work with js.
"files.associations": {
"*.js": "javascript",
"*.jsx": "javascriptreact",
},
"emmet.triggerexpansionontab": true,
"emmet.includelanguages": {
"javascriptreact": "javascriptreact"
},
score:2
it took me two steps to get auto-closing tags in jsx.
- follow kehkashan fazal's instructions above about setting
"emmet.includelanguages"
- download the auto close tag extension from vscode (
formulahendry.auto-close-tag
)
and now you have nice auto-closing jsx tags!
score:2
follow these two steps only:
- on bottom of vscode where detect language click on that
- click on "configure 'javascript(babel)' language based settings..." or what ever
- paste this code on it separate first by comma ',' and save it.
"emmet.includelanguages": {
"javascript": "javascriptreact"
},
"emmet.triggerexpansionontab": true
score:3
adding an item called javascript with value javascriptreact in the emmet section in settings worked for me.
score:3
changing the extension from ".js" to ".jsx" will do the job. but in a case that you want to keep ".js" extension follow below steps.
go to
files > preferences > settings
in the settings tab you will see two tabs named 'user' and 'workspace' (look close to the bottom of search bar). both the tabs will show you same settings but user settings will effect for all the projects in vs code while workspace will effect only for current project. choose whatever option you want, workspace or user.
and then on the left side menu bar you have to go
extensions > json
then at the right side you can see several settings. scroll down a little bit and you will see something like this.
json:schemas
associate schemas to json files in the current project.
edit in settings.json
click on "edit in settigns.json". it will open a json file. add below code to the json file.
"emmet.triggerexpansionontab": true,
"emmet.includelanguages": {
"javascript": "javascriptreact"
}
and save the file. now go and check if your js file supports for jsx auto-completion. this has been tested with
vs code versino 1.61.2.
p.s. -: following part is only for the learners who don't know about json.
copy and paste the above code to the bottom of settings.json file as shown in the following image. don't forget to add a comma (pointed by red arrow) and the code should be pasted before the last closing curly bracket (pointed by yellow arrow).
if you choose workspace settings tab then there might be nothing in you settings.json file. if so just paste the code inside the curly brackets.
score:4
you can use the auto close extention in visual studio code . ps. when you install the extension, the autocomplete won't work until you reload vs code , just reopen vs code , or go to auto close tag extension and click reload.
link of the auto close tag extension
score:5
i went throw all answers and this config worked for me. had to include language as well as add syntaxprofile. without the trigger expansion nothing worked but now i only press tab button to get the result.
"emmet.includelanguages": {
"javascript": "javascriptreact"
},
"emmet.syntaxprofiles": {
"javascript": "jsx"
},
"emmet.triggerexpansionontab": true
score:5
score:6
i solved the problem simply by following the steps below:
- on the left bottom of vscode click to javascript
- then on the top, you will see a list, click on "configure 'javascript' language based settings"
add these lines to the file:
"emmet.triggerexpansionontab": true, "emmet.includelanguages": { "javascript": "javascriptreact" }
if you want to more details, you can check this link.
score:6
score:8
2019 update
auto closing tags in .html, .js, and .jsx
works out of the box. that is, after typing in the closing bracket to the opening tag, the closing tag will be inserted automatically.
emmet with basic html in .jsx files
works out of the box.
emmet with basic html in .js files:
add the following setting, required for emmet abbreviation suggestions, and required for tab expansion to work consistently.
"emmet.includelanguages": {
"javascript": "javascriptreact"
},
emmet with custom tags (e.g. react components) in both .js and .jsx files
add the following setting:
"emmet.triggerexpansionontab": true,
note that with this setting, emmet will expand all words as custom tags (not just react component names)
also note that when using emmet to expand react components as custom tags, you have to actually choose the component name from the suggestion list and complete that first (or type out the whole name manually and close the suggestion menu with the escape key). after the word expands, you then have to tab again to get emmet to expand the custom tag.
there's an active feature request to potentially remove this extra step (automatically expand when selecting the suggestion so that it works the same way as expanding standard html tags would).
troubleshooting
ensure you have the latest version of vscode.
ensure you did not change the following default settings:
"html.autoclosingtags": true,
"javascript.autoclosingtags": true,
"typescript.autoclosingtags": true,
// read the github issue listed above if you're curious why this is required).
"editor.wordbasedsuggestions": true,
// you obviously don't want javascript, javascriptreact included in here if you want emmet to be available in those files
"emmet.excludelanguages": [
"markdown"
],
score:10
none of those solutions worked... but the auto close tag extension does! https://marketplace.visualstudio.com/items?itemname=formulahendry.auto-close-tag
score:12
score:14
2018
i'm using vscode
(ver 1.27.2)
base on my experienced, even though i'm working with react
. the detected language on my vscode
is still vanilla javascript
. and emmet did not work.
- one of the ways to make it work again is change the
vscode
detected language tojavascript react
. this is for singlejs
file only.
- to change it once entirely, you need to associate it.
click configure file association for .js...
and select jsx
, which in my case, i already did.
- for workplace setting, and last if none of them work for you. go to preference of just to
ctrl + , (comma)
to open it.
type and search for emmet
or emmet
. then copy the setting you want to override.
in my case:
{
"emmet.triggerexpansionontab": true,
"emmet.includelanguages": {
"javascript": "javascriptreact"
},
}
note: i didn't try to use jsx
only javascriptreact
.
i implemented the second and third step. and i can now do emmet
.
score:46
just select the appropriate language mode at the bottom-right on the screen: set it to javascript react.
score:57
if someone is still struggling with this issue:
i have discovered that simply setting
"emmet.syntaxprofiles": {
"javascript": "jsx"
},
does not enable html completion. but, using:
"emmet.includelanguages": {
"javascript": "html"
}
does.
according to emmet docs:
"emmet.includelanguages": {}
enable emmet abbreviations in languages that are not supported by default. add a mapping here between the language and emmet supported language.
eg:{"vue-html": "html", "javascript": "javascriptreact"}
score:228
2019: straight-to-the-point answer for react
the most straight-forward way to get jsx/html autocomplete in your react projects is to add this to your user settings or workspace settings (<project-path>/.vscode/settings.json
):
"emmet.includelanguages": {
"javascript": "javascriptreact"
},
"emmet.triggerexpansionontab": true
you may have to restart vs code for the change to take effect.
p.s. if you're not doing this mapping for a react.js project, then kehkashanfazal's answer should probably work for you.
Source: stackoverflow.com
Related Query
- JSX or HTML autocompletion in Visual Studio Code
- Change language to JSX in Visual Studio Code
- 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 changes format (React-JSX)
- Auto Import of React Components in Visual Studio Code
- React intellisense in Visual Studio Code
- Auto Import in Visual Studio Code for React-Native Development
- Setting up proper React Code highlighting in Visual Studio Code?
- Visual Studio Code [eslint] Delete 'CR' [prettier/prettier] on windows
- 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 autocomplete when I press "." key. Any way to disable?
- Visual Studio editing of JSX
- No ESLint configuration found for Visual Studio Code
- Visual Studio code error while saving react files?
- Visual studio code: navigate to jsx components
- Visual Studio Code React not showing error even after adding jsconfig
- Visual Studio Code Intellisense for style CSS in React?
- Visual Studio Code unbound breakpoint Node JS React TypeScript
- Get Visual Studio to recognize the jsx setting from the tsConfig,json
- In Visual Studio 2012, I get warnings and squiggly lines when trying to write JSX with React JS
- Improving JSX Editing in Visual Studio 2017
- In Sublime Text 3, how do you enable Autocompletion of HTML in JSX
- Unable to debug React.js code in visual studio code
- Visual Studio Code extensions stopped working suddenly
- How automatically compile jsx or tsx to js into visual studio code?
- Validation Error In Visual Studio Code with MongoDB
- Visual Studio Code Chrome Debugger doesn't set breakpoints inside generator function in React
More Query from same tag
- How to highlight the current month?
- React - State change of parent does not cause re-rendering of child when passed down as props?
- react-router v4 dispatch redux action on page change
- how to pass useState variable value to array of object field for INSERT data react.js and mysql?
- React calendar not rendering styles
- How to access properties added by mapStateToProps in mapDispatchToProps?
- What's wrong with my onSubmit/handleSubmit method on this Nav.Link?
- How to pass and use query parameters through react router?
- Reflux stores not listening to actions
- react.js trigger event inside another component upon button click
- How to change the value of a variable dynamically, change state and update UI
- MaterialUI: Paper or Card title
- How to pass state to one component to another in different files
- Highlight search term using the indexOf in React
- JS, How can I remove text under conditions of starting at < and ending at >?
- UnhandledPromiseRejectionWarning, but I am handling errors?
- Error: Invalid hook call. Hooks can only be called inside of the body of a function component. (w/ Reactstrap)
- NPM node-sass installation fails
- Use Auth0's hook useAuth0 to get token and set header in Apollo client
- Is it possible to limit the number of items in an array without using slice?
- Access exposed methods via ref
- How to debug my React Recipe Box code?
- React redux frontend not fetching data from Django API with axios
- React Hooks: Refresh data on goBack()
- Is there any way to change the message of empty data in RSuite-table?
- Repeating Edit and Delete Button in React via Mui Datatable
- Linking.canOpenURL returning false when targeting android 30 sdk on React Native
- Assigning an error message in Formik validation in TypeScript not working
- How can I render multiple components interpolating JSX?
- Retrieve information from a route according to the route dynamically