Blog

Notes

React

React notes

A quick summarization of React class

Ragav Kumar V

Ragav Kumar V

Dec 14, 2022 — Updated Feb 5, 2023 · 5 min read

  • JSX - JavaScript XML
  • JSX - JS (Webpack + babel)
  • class is a reserved keyword in JS
  • for, class ➡️ reserved keyword ➡️ htmlFor, className

Bootstraps (start) the react

Msg is displayed when - JS is disabled in the browser

  1. Supports expression
  2. Assignable statement is an expression
  3. Only needed in return
  • Image placeholder
  • Visually impaired people - Screen reader
  • SEO - Ranking

Displays Error in console

  • function should start with a capital letter
  • It should have at least one JSX element

props - properties of the components

  • Avoiding extra elements in the DOM
  • Styling is easier for parent
  • ctrl + ` show / hide terminal
  • ctrl + , settings | format on save on
  • ctrl + c stop react server in terminal
  • win + . emojis
  • crtl + click - for easy navigation
  • React listen to changes made by hooks
  • Hooks - function
  • It starts with use
  • useState
    • const [state, setState] = useState(InitialValue)
    • state - state of mind | state of the art technology | current
    • In App state ➡️ current data
    • setState updates the value of state
    • setState react listens and updates state & view
    • import { useState } from "react";
    • Flow: User clicks ➡️ onClick trigger ➡️ setLike ➡️ React updates view
  • Conditional rendering
  • Conditional styling
  • Copy of the Real Dom
  • Large {key: value}
  • Updating it does not cost performance
  • To access VDOM you could use hooks (eg. setState)
  • Once the update is done on the virtual DOM, then the Real dom is updated
  • Comparison - Reconciliation - VDOM & Real Dom
  • Key helps is quickly compare the changes
  • Don't use document.* in React - Loses performance
  • Typing eventlistner - onChange
  • Flow: User Types ➡️ onChange trigger ➡️ setColor ➡️ React updates view
  • Add Color ➡️ setColorList ➡️ Copy existing colorList & add new color to it
  • Types
    • named imports & exports - preferred
      • Multiple exports
    • default imports & exports
      • Only export per file
  • Always put export at end of the file - good practice
  • crtl + click - for easy navigation
  • npm install @mui/material @emotion/react @emotion/styled
  • npm install @mui/icons-material

_4
<link
_4
rel="stylesheet"
_4
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"
_4
/>


_4
<link
_4
rel="stylesheet"
_4
href="https://fonts.googleapis.com/icon?family=Material+Icons"
_4
/>

npm i react-router-dom

  • Alternate | X -> O -> X | - ✅
  • Board tracking - ✅
  • Winning condition - ✅
    • When player play check in winning condition appears on the board - ✅
    • Announce winner - ✅
    • Stop the game - ✅
  • Link changes URL without refresh
  • Route matches path (URL) -> Component
  • Lifting the state from child to parent
  • Moving the declared state from child to parent
  • Usage Sharing data between sibling components
  • Converts inline style -> internal style
  • Customize material components
  • Available only for material components
  • Conditional rendering
  • Routing
  • Route change cause recreation of component
  • Hence component is mounted, thus useEffect is called
  • Advantage: Keeps data latest

Create, Read, Update & Delete (CRUD) seen in day-to-day life apps

  • Rendering props as JSX
  • Advantage: JSX has access to parentFn variables
  • GET movies gets called, before DELETE completes
  • Will get OLD data
  • .then or await - breaks race condition

Post method - fetch

  1. Method - POST
  2. Data (newMovie) - body & JSON
  3. Header - JSON
  • JSON format - string datatype
  • JS object - object datatype
  • JS object Advantage
    • dot & box syntax
    • function
  • JSON format - cannot have a function
  • Why JSON?
    • Universal format - JS - python - GO

@ragavkumarv
swipe to next ➡️