VSCode auto imports for React Native with JavaScript - javascript

I know VSCode supports auto import for JavaScript.
For some reason, it does not work with React Native. There is even a dedicated section on the VSCode website for this. But it only answers how to fix this problem for Typescript (using allowSyntheticDefaultImports). I want it for JavaScript (ES6).
I tried explicitly setting "javascript.suggest.autoImports": true, in my settings.json but that wouldn't change anything, since true is the default anyways.
How to get auto imports for React Native with JavaScript in VSCode?
PS: This plugin (suggested in this similar question) is also only for TypeScript. Besides that, since VSCode includes auto import out of the box there should be a solution without an extension for RN and JS.

You might have the 'Auto Imports' option disabled.
In VSCode go to Settings and search for 'Auto Imports' option, it should be something like this:
Just activate it if it's disabled and you'll be fine.

Install Auto Imports VSC extension, and enable Auto-imports options(for JS) in the VSC settings (File -> Preferences -> Settings).
You may try ctrl+space (for example, after placing the cursor inside the <Text> element) and select the import element from the displayed options.

For me the issue was neither the plug in nor VSCode.
I tried selecting suggestions with library name besides it and it worked for me. i.e if I want component then I will select Componet react from the suggestion and it worked.

Related

Material UI VSCode autocomplete

i am using material ui and vscode. autocomplete really annoys me when I write styles in makeStyles because it doesn't understand that I'm writing styles as styled components.
For example, he constantly puts ";" where it would be ",". These are trifles, but these trifles appear dozens of times a day.
Tried to find some mui extensions for vscode but couldn't. There was an attempt to use tabnine for autocomplete, and it does the job, but I don't like how tabnine works in general.
By the way, in another project where I use the styled-components library - everything is ok, there vscode successfully copes with autocompletion. I do not understand what can be done with mui.screen
I also thought about trying webstorm, but it seems redundant to switch to another IDE because of this alone.

How to set JSX files default to Babel text highlighting in sublime

I have a babel text highlighting that i added in my sublime. However every time I open a new react project it defaults to javascript text highlighting then i have to reset each javascript file to get the correct text highlighting. As you can see in the lower right of my screenshot it is by default set to javascript.
The syntax that Sublime selects is based primarily on the extension that the file has.
You can select View > Syntax > Open all with current extension as... from the menu while you have such a file open to tell Sublime what syntax you want it to use for any particular extension.
If you sometimes use regular JavaScript as well, you'll experience your current problem in reverse; you will have to manually swap the syntax back to JavaScript.
Either way, the Project Specific Syntax Settings package may also be useful in this case if you use projects. It will allow you to configure per project what you want the syntax for different files to be.
What I did was to make babel(JavaScript) the default, preventing the default JavaScript by adding it as a value to ignored_packages.
To do this, open your sublime, click on Preferences > settings then paste this in:
"ignored_packages":["JavaScript"]
More details here: https://github.com/babel/babel-sublime

Setting up proper React Code highlighting in Visual Studio Code?

I have been trying to find a proper way to highlight React Code in '.js' files so that it is easier to read in Visual Studio Code. The photo below shows a sample file of how a lot of it is in one color, making it hard to read.
I tried using "jsx" extension by TwentyChung and "react-beautify", but neither of them worked. Can someone please assist? :-)
Change the VS CODE color theme to Dark+ and change the language in bottom status bar to java script react. This worked for me
JSX highlighting works out of the box in VS code and JSX files are already associated with JavaScript React language mode. If you want to enable JSX syntax coloring in .js files click on the language name in the status bar and select JavaScript React language mode. You can also associate .js files with JavaScript React if you don't want to do this every time. Make sure you have the latest version of VS Code.
Disabling this extension fixed it for me. It specifically happened this day November 17,2022 3 of my workmates were having the same problem.
Just uninstall this plugin and install it again in the vs code extensions:
Name: JavaScript and TypeScript Nightly
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-vscode.vscode-typescript-next
I just added this to settings.json and it worked for me, so you can give it a try.
"files.associations": {
"*.js": "typescriptreact"
}
For Me Here is what worked
Update the vscode by downloading the latest verrsion
https://code.visualstudio.com/download
2.Open Vscode click extension and search this extension
Javascript Atom Gramar
Just disable the extension.
3.Close and open vscode, now u should see colors in your jsx code.
Hope this will help some one in future
disable the extension named Javascript Atom Grammar works for me
Select Language mode as "Javascript React".
Go to Settings -> Color theme -> Select "Dark+" theme.
Click: Ctrl + K + T
Change the color theme settings to dark+(default) , it worked for me.
And select the appropriate language from bottom status bar:
VS Code highlights code via extensions, not with ESLint or Prettier, which are sometimes assumed to do the job. Out of the box, VS Code supports React and JSX natively. You can also adjust VS Code's settings.json file. Here's an example off how that might look:
{
"window.zoomLevel": 0,
// Solarized-dark theme
"workbench.colorTheme": "Solarized-dark",
// Changes the highlight color in solarized-dark, which I can't see
"workbench.colorCustomizations": {
"editor.selectionBackground": "#5b455e",
"editorBracketMatch.border": "#555",
"editorBracketMatch.background": "#5b455e"
},
// Number of spaces in a tab
"editor.tabSize": 2,
// Insert spaces when pressing Tab. This setting is overriden
// based on the file contents when `editor.detectIndentation` is true.
"editor.insertSpaces": true,
// Override whatever the files say and give me 2 spaces per tab
"editor.detectIndentation": false,
"workbench.startupEditor": "newUntitledFile",
"explorer.confirmDelete": false,
"explorer.confirmDragAndDrop": false,
"javascript.updateImportsOnFileMove.enabled": "always"
}
VS Code modifies syntax highlighting automatically, but it's not perfect. You can also adjust the detection by clicking on the auto-detected language on the right side of the bottom toolbar:

React.js files syntax in sublime text 3

i am using sublime text 3 as my code editor,i have written a basic hello world example in React.but the coloring is improper on the code ,i have tried installing Babel plugin but even after that also the coloring doesn't seem to work ,as you can see the image below
Just installing it isn't enough, you have to also tell SublimeText to use it.
Either do
a) Ctrl-Shift-P, type "Babel" and select Set Syntax: Javascript(Babel)
or
b) Go to the menu and do View->Syntax->Open all with current extension as...->Babel->Javascript(Babel).
You could follow the below mentioned steps:-
Setting babel as the default syntax
To set it as the default syntax for a particular extension:
Open a file with that extension,
Select View from the menu,
Then Syntax -> Open all with current extension as... -> Babel -> JavaScript (Babel).
Repeat this for each extension (e.g.: .js and .jsx).
Setting a Color Scheme
Babel comes bundled with Next and Monokai from Benvie/JavaScriptNext.tmLanguage. Select one from Preferences -> Color Scheme -> Babel
Courtesy: https://github.com/babel/babel-sublime
This might possibly help you out...follow below steps
press Ctrl + Shift + P
Doing so, Command Palette pops up and there type : Package control . And then
select the option Package Control: install package
Now typein and select 'Babel'
Now open 'View' menu and Navigate to Syntax, Open all with current extension
as…, Babel, Javascript (Babel).

Disable ckeditor context menu in version 4.4.6

I am using ckeditor in a Rails4 project. I have tried both the ckeditor gem and the ckeditor_rails gem to provide the ckeditor libraries.
There are multiple posts here by people wanting to remove the ckeditor context menu so that the native browser context menu can be displayed.
This is usually to enable the browser spellchecker to be used rather than the ckeditor paid / advertised spellchecker.
how-to-remove-contextmenu-in-ckeditor-4-3
ckeditor-3-6-3-enable-browser-spellcheck-and-disable-context-menu
how-to-disable-ckeditor-context-menu/20229730#20229730
The third link has the most replies but none of them are universally accepted.
Generally the reply is to remove the contextmenu plugin by placing the following in the ckeditor config.js
config.removePlugins = 'contextmenu';
There is also the suggestion that contextmenu is a dependency on other plugins and different people add a multitude of other plugins to be removed as well.
One helpful post suggests running the following code in the console to establish the dependencies.
$.each(CKEDITOR.plugins, function(k, v){
v.requires && console.log("Plugin '" + k + "' requires: " + v.requires)
})
This seems to work well and suggests that tabletools and liststyle plugin is dependent on contextmenu. So we end up with
config.removePlugins = 'liststyle,tabletools,contextmenu';
Unfortunately this does not disable the context menu in the version of ckeditor that I am using (4.4.6 established by adding alert(CKEDITOR.version) in the config.js)
Finally there is a suggestion to use the following code in config.js
CKEDITOR.on('instanceReady', function(ev) {
ev.editor.editable().addClass('cke_enable_context_menu')
});
There is no suggestion as to how this is meant to disable the context menu but in any case it makes no difference for me.
For me this is a showstopper as the ckeditor context menu hides the browser spelling suggestions and the cut and paste options it contains do not actually work but just bring up the browser dialog.
Your browser security settings don't permit the editor to
automatically execute copying operations. Please use the keyboard for
that (Ctrl/Cmd+C).
In all other aspects ckeditor does seem to be the best functioning editor out there.
In my Drupal 7 environment, loading ckeditor from the CDN, current version is 4.11.4.
The only thing that worked for me after many failed alternatives:
config.removePlugins = 'liststyle,tableselection,tabletools,tableresize,contextmenu';
For convenience, I put this in the module configuration settings -> Advanced -> Custom JavaScript configuration, but in my experience the same result can be achieved in the ckeditor.config.js file in the module folder.
(It's just more likely to get accidentally overwritten there, when updating the module. ... you could also do it by checking the option to use the config.js file in your theme and then adding the line above to that file.)
As simple as that:
CKEDITOR.replace( 'textarea', {
removePlugins: 'contextmenu,tabletools'
} );
If it does not help you, you must include a valid sample to reproduce the issue because something exotic is going on in your setup.
If anyone is looking on how to disable the context menu and have access to the native browser spellchecker in CKEditor:
CKEDITOR.replace( 'editor1', {
removePlugins: 'contextmenu,liststyle,tabletools,tableselection',
disableNativeSpellChecker: false
} );
(tested on CKEditor 4.7.0, standard package)

Categories