Тёмный

React JS Interview Questions ( useThrottle Hook ) - Frontend Machine Coding Interview Experience 

RoadsideCoder
Подписаться 120 тыс.
Просмотров 12 тыс.
50% 1

Опубликовано:

 

28 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 30   
@RoadsideCoder
@RoadsideCoder 7 месяцев назад
🔴 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
@mangeshrakhonde4396 2 месяца назад
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.
@rahuldwivedi4758
@rahuldwivedi4758 28 дней назад
You really don’t need to throttle like that. You don’t need to compare and keep a track of the current time when it runs. It’s look buggy. How about this? const throttle = function(func, delay){ let isRunning = false; return function(…args){ if(!isRunning){ isRunning = true; func.apply(this, args); } setTimeout( ()=> isRunning = false, delay); } }
@yashsolanki069
@yashsolanki069 7 месяцев назад
What if we use debounce lodash func. For this purpose?
@rakib_bhai74
@rakib_bhai74 7 месяцев назад
Will call the api for every event after first event out from call stack till last event
@yashsolanki069
@yashsolanki069 7 месяцев назад
@@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.
@siddhartsingh6606
@siddhartsingh6606 7 месяцев назад
Why delay - (date now() - lastExecruted) as condition for setTimeout
@dhruvdhar1
@dhruvdhar1 Месяц назад
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 }
@akshitagarwal9850
@akshitagarwal9850 2 месяца назад
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.
@rajneeshsaroha1019
@rajneeshsaroha1019 4 месяца назад
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_playz
@Solo_playz 7 месяцев назад
But we can also use the intersection observer API to get this infinite scroll effect right? BTW great video ❤
@yuvarajpandiyans1891
@yuvarajpandiyans1891 3 месяца назад
same feeling
@bloggerayush8550
@bloggerayush8550 6 месяцев назад
Bro, please explain as well...in the last you are directly writing the code ..for a new person it is difficult
@RoadsideCoder
@RoadsideCoder 6 месяцев назад
Noted
@bloggerayush8550
@bloggerayush8550 6 месяцев назад
thanks bhai, please do not take it in a negative way bhai. Bss mujhe lga.....@@RoadsideCoder
@Aviralsingh-yw7xx
@Aviralsingh-yw7xx 7 месяцев назад
Sir pleasedo a todo app with CRUD operations machine coding question.
@heena2002
@heena2002 7 месяцев назад
Great tutorial piyush 🙏 Can you also make one on how to build a voting poll in react js.
@sankalpsachan9199
@sankalpsachan9199 7 месяцев назад
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!
@MrColins710
@MrColins710 7 месяцев назад
cool lesson! thank you
@jacquelynecarmen
@jacquelynecarmen 7 месяцев назад
@RavindraSingh-lp9pl
@RavindraSingh-lp9pl 7 месяцев назад
Superb
@shubhankar-13
@shubhankar-13 7 месяцев назад
Great
@kaushalkumar6666
@kaushalkumar6666 7 месяцев назад
why not use Intersection Observer API ?
@RoadsideCoder
@RoadsideCoder 7 месяцев назад
I will bring that too
@rishiraj2548
@rishiraj2548 7 месяцев назад
👍👍
@kalideb-y3y
@kalideb-y3y 7 месяцев назад
why not use debouncing instead ?
@RoadsideCoder
@RoadsideCoder 7 месяцев назад
They are both separate techniques
@skabadathaque8046
@skabadathaque8046 7 месяцев назад
Denounced hook
@Harsh-fv2kg
@Harsh-fv2kg 6 месяцев назад
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.
Далее
ДЕНЬ УЧИТЕЛЯ В ШКОЛЕ
01:00
Просмотров 1,1 млн
useRef hook in reactjs | Easiest way
19:44
Просмотров 78 тыс.
The React Interview Questions You need to Know
21:29
Просмотров 36 тыс.