🔝 Top 4 Visual Studio Code Extensions for React Developers 👩💻
-
ES7 React/Redux/GraphQL/React-Native snippets
Publisher: dsznajder
Use React snippets to speed up your React game!
Install using 按Ctrl+P
ext install dsznajder.es7-react-js-snippetsSome useful snippets
imp➡import moduleName from 'module'imd➡import { destructuredModule } from 'module'rfce⬇
import React from 'react'function ComponentName() {
return (
<div></div>
)
}export default ComponentName
-
ESLint
Publisher: Dirk Baeumer
ESLint finds and fixes problems in JavaScript code. ESLint requires to be run from the command. This VSC extension checks your code on the fly. ESLint can fix code when the file is saved.
Install this extension using 按Ctrl+P
ext install dbaeumer.vscode-eslintInstall ESLint into your React project…
npm install eslint --save-devIf you used
npx create-react-app app-nameto create your react app then you are good to go with the basic React ESLint configuration as thepackage.jsonfile already has the ESlint configuration. Usenpx eslint --initto create a .eslintrc file with alternate configurations.如果您已创建 .eslintrc.json 文件, 然后添加以下规则以允许react中的js扩展.
"rules": {
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"react/react-in-jsx-scope": "off",
"react/jsx-one-expression-per-line": [0, { "allow": "literal" }] "no-unused-vars": [1, { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }]}
将以下内容添加到您的 VSC 设置中 (按Ctrl+, ➡ 点击打开设置图标), 在保存时运行 ESLint, 并将 VSC 设置为 lf 中的结束行,这样 ESLint 就不会抱怨.
"files.eol": "\n",
"editor.codeActionsOnSave": {
"source.fixAll": true
}
-
更漂亮 – 代码格式化程序
Publisher: 更漂亮
将代码格式化为一致以便于阅读.
Prettier 可以格式化 JavaScript, 打字稿, JSX, HTML, CSS, GraphQL, Markdown 和 YAML.
ESLint 还可以格式化您的 JavaScript 和 React 代码. 因此, 我建议您设置 ESLint 来格式化 JavaScript 和 React 文件, 然后使用 Prettier 格式化你的 CSS, JSON, React 中的 GraphQL 和 Markdown.
Prettier 需要命令行才能在您的代码上运行. 保存代码文件时,此 VSC 扩展将格式化您的代码.
Install this extension using 按Ctrl+P
ext install esbenp.prettier-vscode将 Prettier 安装到您的项目中…
npm install --save-dev --save-exact prettier创建一个
.prettierrc.jsonfile to your React project root to create custom formatting rules.
{
"trailingComma": "es5",
"semi": true,
"singleQuote": true,
"jsxSingleQuote": true,
"printWidth": 120
}
去 Prettier site for more config. 规则.
将以下内容添加到您的 VSC 设置中 (按Ctrl+, ➡ 点击打开设置图标), to format on save, disable on JavaScript and React code.
"editor.defaultFormatter": "esbenp.prettier-vscode",
"prettier.disableLanguages": ["javascript", "javascriptreact"] -
Rainbow Brackets
Publisher: 2gua
Sets different colours to round, square and curly brackets. This allows you to easily visually match bracket pairs in your React code.
Install this extension using 按Ctrl+P
ext install 2gua.rainbow-brackets
