Developing React with VSCode
Visual Studio Code (abbreviated as VS Code) is a free, open-source code editor developed by Microsoft that supports multiple programming languages and provides features such as syntax highlighting, intelligent code completion, code refactoring, and debugging.
VS Code has a built-in terminal that lets you run command-line tools such as npm and yarn directly in the editor, making project building and management convenient.
If you want a richer Vue.js development environment, you can install the Volar and Volar for TypeScript extensions, which provide Vue.js intelligent hints.
If you are not yet familiar with VS Code or have not installed it, you can refer to:VSCode Tutorial。
Why choose VS Code for React development?
- Intelligent completion: Perfect support for JSX, React Hooks, props, and more.
- Rich extensions: One-click installation of ESLint, Prettier, code snippets, and more to boost efficiency.
- Integrated terminal: Run directly in the editor
npm run devand other commands. - Debugging tools: Built-in debugger combined with React DevTools for an excellent experience.
- Cross-platform: Perfect support for Windows, macOS, and Linux.
- Free and open source: Maintained by Microsoft with an active community.
Downloading and Installing VS Code
-
Visit the official site:https://code.visualstudio.com/
-
Click the big Download button and select your operating system:
- Windows: Download the .exe installer
- macOS: Download the .dmg (drag to Applications)
- Linux: Choose .deb or .rpm depending on your distribution
-
Installation process:
- Windows/macOS: Double-click the installer and click Next/Continue throughout.
- It is recommended to check "Add to PATH" and "Register as code editor" (for easy command-line opening).
-
Verify installation:
- Open VS Code, and you will see the welcome screen.
- Windows users can type in the command line
code --versionto test.
Open Your React Project
-
Open VS Code.
-
Method 1: Menu File → Open Folder, select your project folder (for example
my-first-react-app)。 -
Method 2 (recommended): Enter the project directory in the terminal, then open it in one step:
cd my-first-react-app
code .
(code . The command will open the current folder directly in VS Code)
Now you see the file explorer on the left, showing the project structure (such as src, public, etc.).

Installing Essential Extensions
The power of VS Code lies in its extensions. Click the Extensions icon (four squares) in the left activity bar, or press the shortcut Ctrl+Shift+X(macOS: Cmd+Shift+X) to open the Extensions marketplace.
Search for and install the following extensions (click Install):

-
ESLint(Author: Microsoft)
- Real-time code standard checking, officially recommended by React.
- After installation, errors are highlighted in red in the code.
-
Prettier - Code formatter(Author: Prettier)
- Automatically formats code to keep a consistent style.
-
ES7+ React/Redux/React-Native snippets(Author: dsznajder)
- A handy code snippet tool! Type a shortcut to quickly generate components.
- Common snippets:
rafce→ Generate arrow function component + export defaultrfc→ Generate function componentuseState→ Quickly generate useState
rafce→ Generate arrow function component + export defaultrfc→ Generate function componentuseState→ Quickly generate useState
-
Path Intellisense(Author: Christian Kohler)
- Auto-completion for import paths (super useful when importing).
-
Bracket Pair Colorizer 2 Or use the built-in bracket colorization (built into VS Code 1.60+)
- Brackets are distinguished by color, making nested JSX easier to read.
-
GitLens(Optional, but strongly recommended)
- Git enhancement, view code commit history.
React-specific recommendations(Optional, advanced):
- Tailwind CSS IntelliSense(If using Tailwind)
- React Developer Tools(Browser extension already installed, not needed here)
After installation, restart VS Code (or press Ctrl+Shift+P → Reload Window)。
Configure VS Code to improve the React development experience
Press Ctrl+Shift+P(macOS: Cmd+Shift+P) to open the Command Palette, type "Preferences: Open Settings (JSON)" to open settings.json。
Create in the project root directory .vscode/settings.json(Project-level configuration is recommended), add the following:
{
// Auto-format on save
"editor.formatOnSave": true,
// Default to Prettier formatting
"editor.defaultFormatter": "esbenp.prettier-vscode",
// ESLint auto-fix
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
// JSX/TSX files also apply Prettier
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
// Show line numbers, indentation guide
"editor.rulers": [80],
"editor.guides.indentation": true
}
Takes effect after saving. Now every time you save code, Prettier will automatically format it and ESLint will automatically fix common problems.
Validation: Deliberately write a piece of non-standard code (such as a missing semicolon), then save and see if it is automatically fixed.
Actually writing React code: creating a component from scratch
In the Explorer on the left, right-click src the folder → New Folder → Create components folder.
Right-click components → New File → Create Greeting.jsx。
Use code snippets to quickly generate a component:
- Input
rafce(react arrow function component export) - Press the Tab key to automatically generate the template:
import React from 'react'
const Greeting = () => {
return (
Greeting
)
}
export default Greeting
Modify it into a complete component (demonstrating state and Props):
Example
import
{
useState
}
from
'react'
;
const
Greeting
=
(
{
name
=
'Stranger'
}
)
=>
{
const
[
count
,
setCount
]
=
useState
(
0
)
;
return
(
<
div style
=
{
{
padding
:
'20px'
,
border
:
'1px solid #ccc'
}
}
<
h2
Hello,
{
name
}!
h2
<
p
You have clicked
{
count
}
times
p
<
button onClick
=
{
(
)
=>
setCount
(
count
1
)
}
Click me
1
button
div
)
;
}
;
export
default
Greeting
;
in src/App.jsx Import and use it in:
Example
import
Greeting from
'./components/Greeting.jsx'
;
// Add in return:
<
div
<Greeting name
=
"Runoob"
/>
<
Greeting
/>
{/* Use default name */
}
div
Save all files (Ctrl+S), switch to the browser, and hot reload will automatically display the new component!
Experience highlights:
- Input
useState, IntelliSense will provide hints. - Import path
./components/Greeting.jsx, Path Intellisense will auto-complete it. - After saving, Prettier automatically formats the indentation.
- If there are errors, ESLint will highlight them in red in the Problems panel (at the bottom).
Integrated terminal and debugging tips
Built-in terminal: Menu Terminal → New Terminal, or Ctrl+` (backtick).
- Run directly
pnpm dev, the server output appears here.
Debugging React code:
- Install the browser extension React Developer Tools(if not already installed).
- In VS Code, press F5 to start debugging (requires configuring launch.json first, but at the beginner stage, use browser DevTools first).
- In the browser, press F12 → the Components tab to view the Props and state of your Greeting component.
Common shortcuts(must memorize):
- Ctrl + S: Save
- Ctrl + /: Comment line
- Alt + ↑/↓: Move line
- Ctrl + D: Multi-cursor select same word
- Ctrl + Shift + P: Command Palette (all-purpose)
Small exercise: build a card component
- creation
components/Card.jsx, userafceto generate. - to implement a card component that receives three Props: title, content, and imageUrl.
- Use it twice in App.jsx, showing different content.
- Add some inline styles for beautification.
When done, your page will have multiple beautiful cards!
Step 1: Create the Card.jsx component
-
in
srcUnder the folder, right-click → New Folder → Createcomponentsfolder (if it doesn't exist yet). -
Right-click
componentsfolder → New File → CreateCard.jsx。 -
in
Card.jsx, enterrafce(press Tab to auto-generate the template), then modify it into the following code:
Card.jsx file code:
import
React from
'react'
;
const
Card
=
(
{
title
,
content
,
imageUrl
}
)
=>
{
return
(
<
div
style
=
{
{
width:
'300px'
,
border
:
'1px solid #ccc'
,
borderRadius
:
'12px'
,
overflow
:
'hidden'
,
boxShadow
:
'0 4px 12px rgba(0, 0, 0, 0.1)'
,
margin
:
'20px auto'
,
backgroundColor
:
'#fff'
,
fontFamily
:
'Arial, sans-serif'
,
}
}
{
imageUrl
&&
(
<
img
src
=
{
imageUrl
}
alt
=
{
title
}
style
=
{
{
width:
'100%'
,
height
:
'200px'
,
objectFit
:
'cover'
,
}
}
/>
)
}
<
div style
=
{
{
padding
:
'20px'
}
}
<
h3 style
=
{
{
margin
:
'0 0 10px 0'
,
color
:
'#333'
}
}
{
title
}
h3
<
p style
=
{
{
margin
:
0
,
color
:
'#666'
,
lineHeight
:
'1.5'
}
}
{
content
}
p
div
div
)
;
}
;
export
default
Card
;
Description:
- Use destructured Props:
{ title, content, imageUrl }。 - Inline style beautification: rounded corners, shadows, responsive images, spacing, etc., making the card look modern and professional.
- Conditional rendering of the image: if there is no
imageUrl, don't display the image (use&&to implement).
Step 2: Modify App.jsx to use the Card component twice
Open src/App.jsx, replace the content with the following code (keeps part of the original structure, removes the default counter, and focuses on card display):
src/App.jsx file code:
import
'./App.css'
;
import
Card from
'./components/Card.jsx'
;
function
App
(
)
{
return
(
<
div
style
=
{
{
display:
'flex'
,
flexWrap
:
'wrap'
,
justifyContent
:
'center'
,
padding
:
'40px'
,
backgroundColor
:
'#f0f0f0'
,
minHeight
:
'100vh'
,
}
}
{
/* First card: About React */
}
<
Card
title
="What is React?"
content
=
"React is a JavaScript library for building user interfaces, developed by Facebook. It uses a component-based approach, making code easier to reuse and maintain."
imageUrl
=
"https://react.dev/images/uwu.png"
/>
{
/* Second card: About Vite */
}
<
Card
title
="Advantages of Vite"
content
=
"Vite is a new generation front-end build tool, with an extremely fast dev server startup, support for Hot Module Replacement (HMR), and is the top choice for modern React projects."
imageUrl
=
"https://vite.dev/logo-without-border.svg"
/>
{
/* You can add a third one to try! */
}
div
)
;
}
export
default
App
;
Description:
- Import
Cardwidget. - Use
twice, passing different Props. - The outer div of App uses flex layout so that multiple cards are arranged horizontally (with responsive wrapping).
- The image URLs use official public images (React's small icon and Vite's Logo), requiring no local resources and loading directly online.

Step 3: Run and view the result
- Save all files (Ctrl+S).
- If the dev server isn't running, execute in the VS Code terminal:
npm run dev
- Open http://localhost:5173 in the browser, and you'll see two (or more) beautiful cards, centered, with images, titles, and content!
Result preview (text description):
- The cards have shadows and rounded corners, giving them a Material Design look.
- The image at the top spans the full width, and the text section has comfortable spacing.
- The background is light gray, the cards are white, and the visuals are clear.