React Custom Hooks: useDebounce - Simply Explained!

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ก.ค. 2023
  • Join The Discord! → discord.cosdensolutions.io
    Source Code → github.com/cosdensolutions/co...
    In this video we will learn about custom React hooks, starting with useDebounce. This is a powerful hook to use when you need to delay the updating of a value by a set amount of time. It's useful when you have a fetch being triggered by a input field and you don't want to fire a new request every time the input. We're going to see the problem, come up with a solution, and then use the custom useDebounce hook to fix it. Enjoy!

ความคิดเห็น • 74

  • @cosdensolutions
    @cosdensolutions  4 หลายเดือนก่อน +1

    Hey everyone! I just launched 🚀 Project React, which is a course that teaches you React by building a real-world project. It goes way beyond what you see in these videos and walks you through step-by-step on how to build a big and complex application with React! You can check it out here: cosden.solutions/project-react

  • @PrashantKumar-rc5hl
    @PrashantKumar-rc5hl 21 ชั่วโมงที่ผ่านมา

    That is very nice and clean explanation every second was crucial, thanks for making the TH-cam community strong by putting exactly to-the-point videos

  • @codingispower1816
    @codingispower1816 7 หลายเดือนก่อน +20

    Dude, if you made a full react course with testing and all of the adv concepts, i'd pay for it. Your teaching styleis clear and concise and you don't gloss over the important parts AND you did it in TS? Sheesh. Legend.

    • @cosdensolutions
      @cosdensolutions  7 หลายเดือนก่อน +5

      Oh but I am making one :) stay tuned

    • @codingispower1816
      @codingispower1816 7 หลายเดือนก่อน

      I can't wait!@@cosdensolutions

    • @sagardas4218
      @sagardas4218 4 หลายเดือนก่อน

      @@cosdensolutions Hey bro make Next Js + Typescript course

    • @user-eo1tc2sd9y
      @user-eo1tc2sd9y 2 หลายเดือนก่อน

      I hope you won't forget your youtube tagline which says "best react content on youtube" apart from paid course.

  • @GavHTFC
    @GavHTFC 9 หลายเดือนก่อน +1

    Darius you lifesaver, I just knew when searching "react debounce" that you'd come up in the results, and that your solution would work! I wasn't approaching debouncing in the best way admittedly, and you've put me back on the straight and narrow, keep it up!

    • @cosdensolutions
      @cosdensolutions  9 หลายเดือนก่อน +2

      damn, thank you for the kind words! really glad you find the videos useful!

  • @brandonyippp
    @brandonyippp หลายเดือนก่อน +1

    Seriously underrated channel, thank you so much for your continuous content!

  • @prashlovessamosa
    @prashlovessamosa 11 หลายเดือนก่อน +1

    You are one of the finest teacher I have found on yt the way you explain stuff amazing thanks sir
    Excited for upcoming stuff.

    • @cosdensolutions
      @cosdensolutions  11 หลายเดือนก่อน

      Thanks for the comment!

  • @MohammedShibincp
    @MohammedShibincp 10 หลายเดือนก่อน +1

    I see a lot of videos on TH-cam, but I can’t understand anything. But in this video, I understand everything about custom hooks. thanks sir

    • @cosdensolutions
      @cosdensolutions  10 หลายเดือนก่อน +1

      really glad to hear it!

  • @garikmelqonyan6011
    @garikmelqonyan6011 10 หลายเดือนก่อน

    Good job, bro. Makes tons of sense

  • @letthesuntalk
    @letthesuntalk 8 หลายเดือนก่อน

    really nice, I've been learning a lot from your videos.

  • @katrin_awsm
    @katrin_awsm 28 วันที่ผ่านมา

    Thank you very much! Very useful and understandable

  • @hilkiahlavinier
    @hilkiahlavinier ปีที่แล้ว +1

    Nicely explained!

  • @ravisankarp61
    @ravisankarp61 9 หลายเดือนก่อน

    Excellent and I loved ur videos and channel.

  • @igorbarbosa5331
    @igorbarbosa5331 8 หลายเดือนก่อน

    Perfect explanation!

  • @brNoMundo123
    @brNoMundo123 5 หลายเดือนก่อน

    Eu amei o vídeo! ❤seu conteúdo é demais!

  • @_briantravis
    @_briantravis 6 หลายเดือนก่อน

    Exactly what I was looking for :D

    • @_briantravis
      @_briantravis 6 หลายเดือนก่อน

      what vscode theme are you using?

  • @amankriet
    @amankriet 2 หลายเดือนก่อน

    Thanks a lot. The debounce function was not working in React and now I know why and how to do it.

  • @HojjatAfsharan
    @HojjatAfsharan 9 หลายเดือนก่อน

    Perfect tutorial! thanks

    • @cosdensolutions
      @cosdensolutions  9 หลายเดือนก่อน

      yes you're totally correct!

  • @kelvinnwachukwu8141
    @kelvinnwachukwu8141 5 หลายเดือนก่อน

    This is awesome as your videos has helped me alot

    • @kelvinnwachukwu8141
      @kelvinnwachukwu8141 5 หลายเดือนก่อน

      Please could you also do an example using lodash

  • @chrishanthacosta4093
    @chrishanthacosta4093 หลายเดือนก่อน

    good explanation bro..

  • @sunilmg723
    @sunilmg723 ปีที่แล้ว

    Thanks you so much bro ❤ nice explaination can you please do a detailed video on react virtualization

  • @prashantbharati1867
    @prashantbharati1867 21 ชั่วโมงที่ผ่านมา

    Beautiful ❤

  • @thatkannurgirl
    @thatkannurgirl 5 หลายเดือนก่อน

    So helpful ❤

  • @user-tu1lx6vz9p
    @user-tu1lx6vz9p ปีที่แล้ว

    Nice Man great excellant

  • @MEET4RIDE
    @MEET4RIDE 11 หลายเดือนก่อน

    Many Thanks!

  • @icoderdev
    @icoderdev ปีที่แล้ว +1

    The is so much helpful, thanks so much.

  • @AbdelrahmanSameeh
    @AbdelrahmanSameeh 5 หลายเดือนก่อน

    nice work

  • @alvinacosta2312
    @alvinacosta2312 9 หลายเดือนก่อน

    hello good sir, may i just ask the difference of adding 'search' as value prop for your input as compared to not using the value prop but still using setSearch in the onChange? is it the same or which one is better? thank you

  • @Andres-Estrella
    @Andres-Estrella หลายเดือนก่อน

    thanks !

  • @xgenious
    @xgenious 4 หลายเดือนก่อน

    useful tips

  • @gamersdepo3892
    @gamersdepo3892 ปีที่แล้ว

    Hey, your videos are so nicely explained, I just want to request you one thing, could you please make a explanation video about the MERN stack, and how much knowledge do we need to gain to land a job as the MERN stack developer? like in every field, react, express, mongodb, and node.

    • @cosdensolutions
      @cosdensolutions  ปีที่แล้ว

      the only thing is I'm more focused on React specifically for now, not dabbling too much into DB or backend stuff. Will do more of that once server components are more prominent in the industry 🤙

  • @billyfigueroa1617
    @billyfigueroa1617 6 หลายเดือนก่อน

    Great video. Typically in react we load all the users when we load the page so when we are doing a search we are searching through the state on the fronted
    Nowadays, this type of issue, seems to be more realistic in an older styled app but if I am wrong, please correct me

  • @helenasdiaries515
    @helenasdiaries515 6 หลายเดือนก่อน

    cool thanks

  • @nfaical3
    @nfaical3 7 หลายเดือนก่อน

    Thanks 👍

  • @codingispower1816
    @codingispower1816 7 หลายเดือนก่อน

    Can you do a video on Higher order components? You teach well.

  • @AbsolutePain
    @AbsolutePain 9 หลายเดือนก่อน

    Thanks ! The explaination was clear and crisp . Can you make a video on how to organize /file sturucture your api calls using tanquery || custom hooks . Can we have like only 4 custom hooks for crud api calls ? i just want to learn prod level things from you . Thanks for the great vid

    • @cosdensolutions
      @cosdensolutions  9 หลายเดือนก่อน

      will add it to the list! But also, I'm currently working on a course that will build a big project meant for production, so there will be tons to learn there too!

  • @jubyaid1235
    @jubyaid1235 2 หลายเดือนก่อน

    what is the chat gpt add on being used?

  • @IbanTheOne
    @IbanTheOne 13 วันที่ผ่านมา

    Could it be used the startTransition for this? I've been testing, and I don't think is pretty useful for this case.

  • @matteo6056
    @matteo6056 7 หลายเดือนก่อน

    Great videos, but isn't your useDebounce hooks same as Reacts useDeferred hook with possibility to set up timeout?

    • @cosdensolutions
      @cosdensolutions  7 หลายเดือนก่อน

      yes, useDebounce is the same thing but works through a delay. useDeferredValue is handled automatically through React without a fixed delay

  • @imadimad8814
    @imadimad8814 6 หลายเดือนก่อน

    Can we use useRef hook to do the same thing

  • @shub226
    @shub226 10 หลายเดือนก่อน

    Easiest implementation of Debounce Search

  • @int0therain44
    @int0therain44 5 หลายเดือนก่อน

    Just a question. Isn't it better, to use import { debounce } from 'lodash'; ? it gave a lot of features. What is your opinion when looking at the documentation ?
    Thank !

    • @cosdensolutions
      @cosdensolutions  5 หลายเดือนก่อน +1

      You can, but it is a big library and if you don't use a lot of its functions, sometimes its easier to just write it yourself

    • @int0therain44
      @int0therain44 5 หลายเดือนก่อน

      @@cosdensolutions Thank for your reply ! I finally ended up using this :
      import { useDebounce, useDebouncedCallback, useThrottledCallback } from "use-debounce";
      This is a light npm library in typescript.

  • @jritzeku
    @jritzeku 9 หลายเดือนก่อน

    Can you use useDebounce with formik ?Im currently having an issue where every keystroke in form field causes component to re-render like 2-3 times. Apparently it's a known issue with formik that is unresolved. Perhaps useDebounce can be used here.

    • @cosdensolutions
      @cosdensolutions  9 หลายเดือนก่อน +1

      to do that, you would have to create your own input components that make use of useDebounce and manually update the state debounced! You could also try RHF as an alternative to Formik for better perf

  • @hrutikdhumal402
    @hrutikdhumal402 11 หลายเดือนก่อน

    ❤❤❤

  • @icoderdev
    @icoderdev ปีที่แล้ว

  • @roanacedev
    @roanacedev ปีที่แล้ว

    ❤❤

  • @minhnguyendung4453
    @minhnguyendung4453 ปีที่แล้ว +1

    I hope you make a seri to teach async JavaScript (promise, async await,...) I don't understand how it's works

  • @katejohnson6411
    @katejohnson6411 8 หลายเดือนก่อน

    Why doesn't it trigger on the first letter "render", maybe I don't correctly understand exactly.

    • @cosdensolutions
      @cosdensolutions  8 หลายเดือนก่อน

      Because it defers triggering until when the ms have elapsed!

  • @helenasdiaries515
    @helenasdiaries515 6 หลายเดือนก่อน

    it says I cant accept the invite to discord(((

    • @cosdensolutions
      @cosdensolutions  6 หลายเดือนก่อน

      it should work, maybe try a different browser?

  • @saqibmuhammad7218
    @saqibmuhammad7218 11 หลายเดือนก่อน

    LOL❤‍🔥

  • @xthesly
    @xthesly 9 หลายเดือนก่อน

    Hi, better use fetch abortion ?

  • @user-dd7kw3ym5i
    @user-dd7kw3ym5i 6 หลายเดือนก่อน

    I wanna know why you used hooks in useDebounce? It works without them like this.....
    **********************************
    let timeId;
    function useDebounce(functionToDelay, delay == 1000) {
    clearTimeout(timeId)
    timeId = setTimeout(() => {
    functionToDelay()
    }, delay);
    }
    export default useDebounce
    // then import the useDebounce and put it inside of the useEffect
    **********************************

    • @cosdensolutions
      @cosdensolutions  6 หลายเดือนก่อน +1

      well, based on "// then import the useDebounce and put it inside of the useEffect", you're also using hooks. You basically have to use hooks to implement this

    • @user-dd7kw3ym5i
      @user-dd7kw3ym5i 6 หลายเดือนก่อน

      @@cosdensolutions I mean there's no hooks inside the body of my example

  • @StephenArpad
    @StephenArpad 7 หลายเดือนก่อน

    In my case, I've more than one input compnent.
    In one I type, let's say, the "Zip Code",
    In the one, I type in the "Street Address",
    With this I mean, that I need 2 inputs here, so my call to the API can take place..
    However, when implementing this functionality, I get instead:
    *Warning: Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have a dependency arrar, or one of the depdendecies changes on every render*
    Has anyone experienced this scenario already?
    What solution did you apply?