Skip to main content

Stop Typing import React: Smarter VS Code Snippets for React Devs

Published 2 min readMarkdown
Stop Typing import React: Smarter VS Code Snippets for React Devs

Introduction

I got tired of seeing import React from 'react' at the top of every component file, even when using prebuilt snippets like rafce or rfce. These snippets still include that import, even though it's unnecessary in modern React. Most of the time, it stays unused and gets highlighted as an unused import. Let's be real, in this day and age, nobody writes React.useState. We just write useState and move on.

In this quick guide, I’ll show you how to create a custom VS Code snippet that reflects modern React standards (no extra imports, just clean code). Perfect for speeding up your workflow and writing smarter components.

Step-by-Step Guide

Step One: Open the Snippets File

Press Cmd+Shift+P (Mac) or Ctrl+Shift+P (Windows), then select Snippets: Configure Snippets.

Step 2: Choose JavaScript or TypeScript Snippets

Choose javascriptreact or typescriptreact depending on the files you work with (if it’s jsx then choose javascriptreact, if not then choose typescriptreact).

Step 3: Add Your Custom Snippet

"React Arrow Function Without Import": {
  "prefix": "rafcen",
  "body": [
    "const ${TM_FILENAME_BASE} = () => {",
    "  return (",
    "    <div>$1</div>",
    "  );",
    "};",
    "",
    "export default ${TM_FILENAME_BASE};"
  ],
  "description": "React arrow function without import"
}

Step 4: Use Your New Snippet

In a .jsx or .tsx file, just type rafcen and hit Tab or Enter. And that’s it, you are good to go.

Result Preview

// Type rafcen and then click "Tab" or "Enter" 

const Hero = () => {
  return <div></div>;
};

export default Hero;

Why This Matters?

Customizing your snippets keeps your components clean and aligned with modern React practices. Plus, it's one less thing to delete every time.

Hope this helps speed up your workflow! Feel free to tweak the snippet or create more to match your style.


I’m Temidire. I design and build high-performance frontend experiences where UX, UI, and engineering actually align.

Let’s build smarter.

No comments yet. Be the first to comment.