Intro to React
- JSX- JavaScript XML
- JSX-- JS(Webpack + babel)
Why className?
- classis a reserved keyword in- JS
- for,- class➡️ reserved keyword ➡️- htmlFor,- className
Purpose of index.js
Bootstraps (start) the react
<noscript></noscript>
Msg is displayed when - JS is disabled in the browser
Template syntax ➡️ {}
- Supports expression
- Assignable statement is an expression
- Only needed inreturn
Why alt?
- Image placeholder
- Visually impaired people - Screen reader
- SEO - Ranking
React.StrictMode - Error checking
Displays Error in console
function to be considered as a component
- function should start with a capital letter
- It should have at least oneJSXelement
props ➡️ arguments
props - properties of the components
React fragment <></> or div
- Avoiding extra elements in theDOM
- Styling is easier for parent
Handy shortcuts
- ctrl + `show / hide terminal
- ctrl + ,settings | format on save- on
- ctrl + cstop react server in terminal
- win + .emojis
- crtl + click- for easy navigation
Hooks
- React listen to changes made by hooks
- Hooks - function
- It starts withuse
- useState- const [state, setState] = useState(InitialValue)
- state - state of mind | state of the art technology | current
- In App state ➡️ current data
- setStateupdates the value of- state
- setStatereact listens and updates- state& view
- import { useState } from "react";
- Flow: User clicks ➡️onClicktrigger ➡️setLike➡️ React updates view
 
Toggle element
- Conditional rendering
- Conditional styling
Virtual DOM
- 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 usedocument.*in React - Loses performance
Color game
- Typingeventlistner-onChange
- Flow: User Types ➡️onChangetrigger ➡️setColor➡️ React updates view
- Add Color ➡️setColorList➡️ Copy existingcolorList& add new color to it
imports & exports
- 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
Material installation
- 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/>
React router
npm i react-router-dom
Tic Tac Toe
- Alternate | X -> O -> X | - ✅
- Board tracking - ✅
- Winning condition - ✅- When player play check in winning condition appears on the board - ✅
- Announce winner - ✅
- Stop the game - ✅
 
Routing
- Linkchanges URL without refresh
- Routematches- path(URL) ->- Component
Lifting the state up
- Lifting the state from child to parent
- Moving the declared state from child to parent
- Usage Sharing data between sibling components
sx
- Converts inline style->internal style
- Customize material components
- Available only for material components
Unmounting phase
- Conditional rendering
- Routing
Data re-fetch
- Route change cause recreation of component
- Hence component is mounted, thususeEffectis called
- Advantage: Keeps data latest
Create, Read, Update & Delete (CRUD) seen in day-to-day life apps
renderProps
- Rendering props asJSX
- Advantage:JSXhas access toparentFnvariables
Race Condition
- GETmovies gets called, before- DELETEcompletes
- Will get OLD data
- .thenor- await- breaks race condition
Post method - fetch
- Method -POST
- Data (newMovie) - body &JSON
- Header -JSON
JSON vs JS object
- JSONformat - string datatype
- JS object - object datatype
- JS object Advantage- dot&- boxsyntax
- function
 
- JSONformat - cannot have a- function
- WhyJSON?- Universal format -JS-python-GO
 
@ragavkumarv
swipe to next ➡️
