React Basics


Setup

After running create-react-app,

  1. All packages are listed in package.json.
  2. Delete all src files except index.js.
  3. Structure of the project,
  4. flowchart TB subgraph a[Project] direction TB subgraph b[src] direction LR A[App.js] --> B[index.js] subgraph b1[components] direction TB subgraph b11[CustomButton] direction LR B11[styles.js] --> B12[CustomButton.jsx] end subgraph b12[Graph] direction LR B13[styles.js] --> B14[Graph.jsx] end b11 --> B1[index.js] b12 --> B1 end b1 --> A end subgraph c[public] direction LR C[index.html]; end B --> C; D[package.json] end;

Syntax

  1. index.js (Don't need to touch most of the time)
  2. 
    import React from "react"
    import ReactDOM from "react-dom"
    import App from './components/App'
    
    const reactContentRoot = document.getElementById("root")
    
    ReactDOM.render(<App/>, reactContentRoot)
        
  3. App.js
  4. 
    import React from "react"
    import customButton from "./customButton"
    
    const App = () => {
        return {
            <p> I am Leo. </>
        }
    }
    export default App
        
  5. Functions
  6. 
    const funcname = (arg1,arg2) => {
        return x
    }
        
  7. Import
  8. 
    import x,{a,b} from y
        
  9. Export
  10. 
    export default jsscriptname
        
  11. Hooks
  12. 
    var,setter = useState(initial_var)
    useEffect
        
  13. .css, just normal css script
  14. 
    import "./customButton.css" # in .js
        
  15. Install external js library
  16. 
    npm install @material-ui/core
    npm install --save package --legacy-peer-deps # if cannot resolve dep
        

Practice app

https://zcemycl.github.io/practice-app/

Useful dependencies

  1. @material-ui/core
  2. @material-ui/icons
  3. @chec/commerce.js
  4. @stripe/react-stripe-js
  5. @stripe/stripe-js
  6. react-router-dom
  7. react-hook-form
  8. react-chartjs-2
  9. react-socket-io
  10. three @react-three/fiber
  11. @react-three/drei
  12. ammojs cannonjs ammo-physics
  13. leaflet react-leaflet react-leaflet-geosearch
  14. 
    ## from package.json
     "browserslist": {
       "production": [
          ">0.2%",
          "not dead",
          "not op_mini all"
        ],
        "development": [
          "last 1 chrome version",
          "last 1 firefox version",
          "last 1 safari version"
        ]
    },
    ## to 
    "browserslist": [
       ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    ##
    sudo rm -r node_modules/.cache
    sudo npm install
    sudo yarn start
        
  15. react-dat-gui

Useful extensions in vscode

  1. Auto Rename Tag
  2. Bracket Pair Colorizer
  3. ES7 React/Redux/GraphQL/React-Native snippets
  4. 
    rafce # generates a basic react template script
        

References


  1. React js in 3.5 hours | Full beginners tutorial
  2. npm react-d3-graph
  3. Graph theory (network) library for visualisation and analysis
  4. Adding infinite nodes with cytoscape
  5. r3f particles
  6. codesandbox -- react-graph-vis
  7. visjs vis-network
  8. How to fix error “Failed to compile : ./node_modules/@react-leaflet/core/esm/path.js 10:41 Module parse failed: Unexpected token (10:41)”