🔴 Get my Complete Frontend Interview Prep course - roadsidecoder.com/course-details ➡ Book an Interview Preparation call with me ( 20% OFF for limited time ) - topmate.io/roadsidecoder
@mangeshrakhonde4396Ай бұрын
I think you have given example of debouncing as window resizing is usecase of debouncing. -Regardless of resizing it will only show output at a certain time means we are delying the function call. -(showing output/exicuting function) only when event pause is usecase of debouncing.
@siddhartsingh66066 ай бұрын
Why delay - (date now() - lastExecruted) as condition for setTimeout
@dhruvdhar19 күн бұрын
why do you need to keep track of prev executed time, why not do something like this instead? export const useThrottle = (inputVal, delay) => { const [throttledVal, setThrottledVal] = useState(inputVal) const timer = useRef(null) useEffect(() => { if(!timer.current) { setThrottledVal(inputVal) timer.current = setTimeout(() => { timer.current = null }, delay) } }, [inputVal, delay]) return throttledVal }
@rajneeshsaroha10193 ай бұрын
Dude 😐, just put a console.log("expensive api call") inside handleResize function, and look out the logs in console, you will get to know the problem with the code. Its an infinite expensive api calls irrespective of the resizing event. But yeah, great efforts, I think somehow we have to remove the use of useState from our custom hook to resolve the code here.
@Solo_playz6 ай бұрын
But we can also use the intersection observer API to get this infinite scroll effect right? BTW great video ❤
@yuvarajpandiyans18912 ай бұрын
same feeling
@heena20026 ай бұрын
Great tutorial piyush 🙏 Can you also make one on how to build a voting poll in react js.
@MrColins7106 ай бұрын
cool lesson! thank you
@akshitagarwal9850Ай бұрын
This code is incorrect. Just add a console.log statement in the handler, and you will see. Not only is it executing the code at every interval even when the window size is not changing, but it also requires the handler to have a new reference to work properly. Please avoid adding misleading videos.
@sankalpsachan91996 ай бұрын
May be they were using intersection observer as i noticed that as soon as i see the load more button at the very bottom the next api is called!
@Aviralsingh-yw7xx6 ай бұрын
Sir pleasedo a todo app with CRUD operations machine coding question.
@RavindraSingh-lp9pl6 ай бұрын
Superb
@bloggerayush85505 ай бұрын
Bro, please explain as well...in the last you are directly writing the code ..for a new person it is difficult
@RoadsideCoder5 ай бұрын
Noted
@bloggerayush85505 ай бұрын
thanks bhai, please do not take it in a negative way bhai. Bss mujhe lga.....@@RoadsideCoder
@user-dd7kw3ym5i6 ай бұрын
why not use debouncing instead ?
@RoadsideCoder6 ай бұрын
They are both separate techniques
@jacquelynecarmen6 ай бұрын
❤
@kaushalkumar66666 ай бұрын
why not use Intersection Observer API ?
@RoadsideCoder6 ай бұрын
I will bring that too
@shubhankar-136 ай бұрын
Great
@yashsolanki0696 ай бұрын
What if we use debounce lodash func. For this purpose?
@rakib_bhai746 ай бұрын
Will call the api for every event after first event out from call stack till last event
@yashsolanki0696 ай бұрын
@@rakib_bhai74 with debounce understanding is that it will only execute the function once the activity is finished i.e. resize within the given delay time. So isn't debouncebetter here. Because with the throttle approach it will be called after time delay constantly right? Here, the reason to choose for debounce because the api call has fetching data and formatting data and then updating UI so due to complex operation i believe debounce would be better.
@rishiraj25486 ай бұрын
👍👍
@Harsh-fv2kg5 ай бұрын
Can any one please explain the code at 15:45? I just passed simple delay as an args instead of delay - (Date.now() - lastExecuted.current). It works fine. Couldn't find any error. What's the point of writing that line? Many thanks in advance.