DEV Community

Cover image for Code 2x Faster in VS Code: Must-Have Customizations for JavaScript & React Developers
Kafeel Ahmad (kaf shekh)
Kafeel Ahmad (kaf shekh)

Posted on

Code 2x Faster in VS Code: Must-Have Customizations for JavaScript & React Developers

If you’re developing with JavaScript or React, Visual Studio Code’s customization features can streamline your workflow and make development faster and smoother. In this guide, we’ll cover must-have snippets and essential settings that every JS and React developer should add to their VS Code setup.

1. Speed Up Development with Custom Snippets ✨

Snippets help you speed up your coding by quickly adding reusable blocks of code. Here are some unique, practical snippets that will make your development process more efficient and enjoyable!

How to Add a Snippet in VS Code:

  1. Open the Command Palette: Press Cmd + Shift + P (Mac) or Ctrl + Shift + P (Windows).
  2. Search for “Preferences: Open User Snippets” and select it.
  3. Choose the relevant language file (e.g., JavaScript for JavaScript snippets or javascript.json for general JS snippets).
  4. Add your snippet in the JSON file that opens up by copying and pasting the examples below.

Snippet Examples

🛠️ “Smart React Component” — A Customizable React Component

This snippet generates a React component template with essential attributes like src and props, perfect for quickly setting up functional components with optional customization.

{
"React Smart Component": {
"prefix": "rsc",
"body": [
"import React from 'react';",
"",
"const ${1:ComponentName} = ({ ${2:props} }) => {",
" return (",
" <div className='${1:componentName}'>",
" <img src='${3:/path/to/image.jpg}' alt='${4:description}' />",
" <p>${5:Your text here}</p>",
" </div>",
" );",
"};",
"",
"export default ${1:ComponentName};"
],
"description": "Creates a customizable React component with img and text"
}
}

🛠️ “Conditional Console Log” — Debugging with Conditional Logging

By typing clog, this snippet creates a console.log statement that only logs if the variable isn't null or undefined, making debugging smarter and less error-prone.

{
"Conditional Console Log": {
"prefix": "clog",
"body": [
"if (${1:variable} !== null && ${1:variable} !== undefined) {",
" console.log('${1:variable}:', ${1:variable});",
"}"
],
"description": "Conditional console.log to check variable before logging"
}
}

🛠️ “API Fetch Snippet” — Template for Fetching API Data

Need a quick fetch setup? Typing apif creates an instant API fetch call with error handling.

{
"API Fetch Call": {
"prefix": "apif",
"body": [
"const fetch${1:Data} = async () => {",
" try {",
" const response = await fetch('${2:https://api.example.com/endpoint}');",
" if (!response.ok) throw new Error('Network response was not ok');",
" const data = await response.json();",
" console.log(data);",
" return data;",
" } catch (error) {",
" console.error('Fetch error:', error);",
" }",
"};"
],
"description": "Basic API fetch call with error handling"
}
}

2. Clean Up Your File Explorer 🚫

JavaScript and React projects often include many large directories (hello, node_modules) that clutter your workspace. Here’s how to hide them to keep your file explorer neat.

🌳 Hiding Unwanted Files and Folders

Add these settings to your settings.json to hide bulky folders like node_modules and .log files:

{
"files.exclude": {
"/node_modules": true,
"/build": true,
"/dist": true,
"/.log": true
},
"search.exclude": {
"/node_modules": true,
"/coverage": true
},
"files.watcherExclude": {
"/node_modules/": true,
"/build/*": true
}
}

⚡ Tip: Excluding files from search and watcher processes can make VS Code run noticeably smoother, especially in large projects.

Key Settings Explained

  • files.exclude: Hides specified files and folders from the file explorer. Here, we’re hiding node_modules, build, dist, and .log files.
  • search.exclude: Excludes these items from search results, making searches faster and more relevant.
  • files.watcherExclude: Prevents VS Code from monitoring changes in certain folders, which improves performance by reducing CPU usage.

These exclusions are particularly useful for React and Node.js projects where node_modules and build folders get large and can slow down your search and editor responsiveness.

3. Make Your Code Beautiful: Consistent Code Style 🎨

Set up VS Code to handle formatting automatically, so your code always looks polished.

🖌️ JavaScript Code Style Settings

Update settings.json to apply the following preferences across all projects:

{
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.formatOnSave": true,
"editor.trimAutoWhitespace": true
}

What These Do:

  • editor.tabSize: Sets your indentation level to 2 spaces, the preferred style for JavaScript.
  • editor.insertSpaces: Uses spaces instead of tabs to keep your formatting uniform.
  • editor.formatOnSave: Formats code automatically on save.
  • editor.trimAutoWhitespace: Removes trailing spaces, keeping code clean.

🪄 Pro Tip: Consider adding a .prettierrc file to your project to share your format settings with teammates, ensuring consistent styling across your entire team.

Final Thoughts 💡

These customizations create a smoother, more efficient workspace where you can focus on the code itself. Take a few minutes to implement these tweaks, and experience the productivity boost firsthand. Small changes can make a big difference.

Top comments (0)