6.2 - Common Hooks in React: Useeffect, Usecallback, Usememo, Custom Hooks Prop Drilling
6.2 - Common Hooks in React: Useeffect, Usecallback, Usememo, Custom Hooks Prop Drilling
1. Side effects
2. Hooks
Two jargons before we start
1. Side effects
2. Hooks
Two jargons before we start
1. Side effects
2. Hooks
Two jargons before we start
You are a car racer that has to do a 100 laps across a stadium
You are allowed to take a pit stop from time to time.
Do you take the stop in b/w every lap? Or do you take a stop after every 10 laps lets say?
Lets start with an example
Pit stop
useEffect
Pit stop
https://gist.github.com/hkirat/d3a74a1f4e 2c92f7a3c0da0c47d9c3
ff
useEffect
Pit stop
Dependency array
When should the callback fn run
1. Tyre burst
2. Tyre pressure is up
3. 10 laps have passed
4. Engine is making a noise
5. Want to change the car
useEffect
https://sum-server.100xdevs.com/todo?id=1
Solution
https://gist.github.com/hkirat/178ab 7b3bc80af5878be7b9a3b7d69
ff
useEffect
useEffect
useEffect
It means remembering some output given an input and not computing it again
useMemo
https://gist.github.com/hkirat/30d07fc535c83ab89b7b9c58b11e 4f
ff
useMemo
https://gist.github.com/hkirat/34c2ddf04284945f7bf0f17cbe8347f6
useCallback
Solution
useE ect, useMemo, useCallback, custom hooks
Prop drilling
ff
Custom hooks
Just like useState, useE ect, you can write your own hooks