React - SolarisJapan/lunaris-wiki GitHub Wiki

Guide and best practices for using the React

Components

  • PascalCased file names ending with .jsx e.g.: MyComponent.jsx
  • Overall all subcomponents must be extracted to a separate file, exported alongside the main component, or defined inside the main component.

Examples

With extracted subcomponent:

// MainComponent.jsx
import { ChildComponent } from './components'; 

const MainComponent = () => {
  return (
    <ChildComponent />
  )
};

export default MainComponent;

Defined inside main component:

// MainComponent.jsx
const MainComponent = () => {
  const childComponent = (
    <div>Hello world!</div>
  );

  return (
    <div>
      {childComponent}
    </div>
  )
};

export default MainComponent;

ESLint

.eslintrc.json:

{
  "env": {
    "es6": true,
    "node": true
  },
  "extends": [
    "plugin:react/recommended",
    "plugin:react-hooks/recommended",
    "airbnb"
  ],
  "globals": {
    "Atomics": "readonly",
    "SharedArrayBuffer": "readonly"
  },
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": 2020,
    "sourceType": "module"
  },
  "plugins": [
    "react"
  ],
  "settings": {
    "import/resolver": "webpack"
  },
  "rules": {
    "no-console": "off",
    "no-undef": "off",
    "arrow-body-style": "off",
    "react/style-prop-object": "off",
    "react/prop-types": "off",
    "react/jsx-filename-extension": "off",
    "react/jsx-props-no-spreading": "off",
    "react/jsx-one-expression-per-line": "off",
    "react/no-array-index-key": "off",
    "jsx-a11y/anchor-is-valid": "off"
  }
}

VSCode Settings

.vscode/settings.json:

{
  "[javascript]": {
    "editor.tabSize": 2,
    "editor.detectIndentation": false,
    "editor.formatOnSave": false,
    "editor.defaultFormatter": "esbenp.prettier-vscode",
  },
  "eslint.validate": [
    "javascript",
    "javascriptreact",  
  ],
}
⚠️ **GitHub.com Fallback** ⚠️