React Js noting summary

unpublished draft
ReactJsEsLint

Overview#

Hooks#

Setup#

General#

Common Configs
{
  "eslint.run": "onSave",
  "eslint.validate": [
      "javascript",
      "javascriptreact",
      "typescript",
      "typescriptreact"
    ],
  "javascript.preferences.quoteStyle": "single",
  "typescript.preferences.quoteStyle": "single",
  "javascript.updateImportsOnFileMove.enabled": "always",
  "typescript.updateImportsOnFileMove.enabled": "always",
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  }
}
Consider settings
{
  "css.lint.unknownAtRules": "ignore",
  "scss.lint.unknownAtRules": "ignore",
}

Create React App#

Script to run
yarn create react-app [app-name] --template typescript # create template, using typescript
yarn add eslint prettier eslint-config-prettier eslint-plugin-prettier eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y @typescript-eslint/eslint-plugin @typescript-eslint/parser --dev
yarn add husky lint-staged --dev
npx husky install # initialize husky
npx husky add .husky/pre-commit "yarn lint-staged" # config before commit, run lint stage with all commit file. (also depend on lint-staged command in package.json file)

Explainations#

Example Files#

Create Next App#

Script to run
yarn create next-app [Your App name] --ts
# eslint was added with ts template
yarn add prettier eslint-config-prettier eslint-plugin-prettier eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y @typescript-eslint/eslint-plugin @typescript-eslint/parser --dev
yarn add husky --dev
yarn husky install
yarn husky add .husky/pre-commit "yarn lint-staged"
yarn add lint-staged --dev
# Add [lint-staged.config.js] file as config can be found in corresponding folder

Example Files#

Tip and Trick#

Import node module in Typescript without type definitions#

testing-library

To avoid resetMock from node_modules add to packages.json
"jest": {
    "resetMocks": false
  }

Khanh Nguyen

Web developer & .Net lover