-
Data is the new oil
-
UI layer & Data layer
-
Data layer
- states & props
- state: local variable/ scope is only within a component
- props: values passed from one component to another component
-
Props Drilling :- Passing props from one component to another which inturn passes to another component
- Example:
AppLayout -> state (user) pass as prop to Body Body -> pass as prop to Body RestaurantCard ->
-
State Lifting (Example of Accrodian & Closing Accordian)
-
React Developer tool [chrome extension]: For Debugging data layer:
- Component (in browser console)
- Profiler (in browser console)
-
Data layer:
- props
- State
- Hooks
- rendered by
- source
- Data from child to parent ?
- Context: for storing a data that we can used throughout application
- why not global variable ?
- Because react will not be able to track and trigger reconciliation
- Create Context in
utils
folder - Creating Context
createContext()
- Using Context:
useContext
(hook)
- Context Consumer: (using context in class based component)
<<ContextName.Consumer>
- Context Provider
<ContextName.Provider value={}>
(Modifing/Overriding)
- To "Display Name" of context in brower console during debugging in React Developer extenion Tools use:
ContextName.displayname = "Name of Context"
- why not global variable ?