React Debounce Search Input API Call | useDebounce React Hook

Поділитися
Вставка
  • Опубліковано 12 вер 2024

КОМЕНТАРІ • 81

  • @DaveGrayTeachesCode
    @DaveGrayTeachesCode  Рік тому +7

    In this tutorial, you will learn how to debounce an input that automatically searches the Wikipedia API. Bonus: you will have a working React search engine app! 💯
    If you have questions, join my Discord server and share your questions there: discord.gg/neKghyefqh

  • @oortcloud210
    @oortcloud210 3 місяці тому +1

    Clear, concise, no silly 'Game Changer!' clickbait titles - thank you! I always look for tutorials by you first if I need sound advice on how to do something well.

  • @khalilbenmeziane8836
    @khalilbenmeziane8836 Рік тому +3

    I learned a lot from you, thank you dave

  • @PolycarpOkock
    @PolycarpOkock Рік тому +1

    We have been using lodash debounce functionality for this, glad to see. Sometimes we used also the throttle just to delay the results

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Рік тому +1

      Glad this may help!

    • @quasi_verum
      @quasi_verum Рік тому +1

      true this shoul be called useDelay, not useDebounce, because in _.debounce the function still being called when the timeout is reached, so if in case we type more than 100 char the function is still being called several time. this good when you use searching suggestion, but bad in calling api, useDelay should be better in using API.

  • @heyjitendra
    @heyjitendra Рік тому +1

    You are a gem Dave. Thank you for making these wonderful practical tutorials and projects.

  • @azadsarxanli
    @azadsarxanli Рік тому +1

    You're just Amazing, Dave! Thanks a lot.

  • @nextleveltech267
    @nextleveltech267 23 дні тому +1

    Thank you, it was usefull❤❤❤❤

  • @7doors847
    @7doors847 Рік тому +1

    Very nice Dave!!👌

  • @TravinskiyVladislav
    @TravinskiyVladislav Рік тому +1

    Thank you, Dave

  • @s3interdev
    @s3interdev Рік тому +1

    Thank you Dave, very helpful.

  • @hungnguyencanh5089
    @hungnguyencanh5089 Рік тому +1

    Thanks, Dave

  • @harag9
    @harag9 11 місяців тому

    Great tutorial, Many thanks for this. I'm currently implementing a similar feature at work and couldn't work it out to only run after x time. Though I could if it was plain javascript back in the day - React mindset is quite different.

  • @adityakunwar1524
    @adityakunwar1524 Рік тому

    was waiting for this video for a long time

  • @zombiefacesupreme
    @zombiefacesupreme Рік тому

    LMAO, I literally figured this out by myself the other day, but it's good to see that my code ended up very similar to yours!

  • @prakharagarwal3530
    @prakharagarwal3530 Рік тому

    Great 💯
    I learned a neat technique to apply Role based Authorization from your authentication and authorisation playlist. thankyou 😊

  • @dr-Jonas-Birch
    @dr-Jonas-Birch Рік тому

    Great series.
    JB

  • @ankitaburman5406
    @ankitaburman5406 Рік тому

    This was so smooth .. Thank you Dave .

  • @PrashantSingh-ug6tv
    @PrashantSingh-ug6tv Рік тому

    Hi Dave, please also make a video on the multiple checkbox filter option as did for search and add to this playlist

  • @rounakmukherjee9540
    @rounakmukherjee9540 Рік тому

    Thank you very much this is something that i am also looking for

  • @sakibcoder
    @sakibcoder Рік тому

    very clean intructions💯

  • @hardwired89
    @hardwired89 Рік тому

    Thank you sir for the tutorial, Need tutorial for react js testing unit / testing tutorial

  • @youssefkarfouh3084
    @youssefkarfouh3084 5 місяців тому

    thank you so much dave

  • @gyglejid
    @gyglejid 2 місяці тому

    Hi!
    I noticed that the List component is re-rendered every time the value in the search field is changed. However, the request goes away after the last change of the List component - is this a feature of useSwr? Will this not work with fetch? Am I right?
    Thx for video and your work!

  • @baconovertures1675
    @baconovertures1675 Рік тому

    Thanks Dave!

  • @The.mohisa
    @The.mohisa Рік тому

    thanke you that's really helpful

  • @romimaximus
    @romimaximus Рік тому

    I really wish you could, ..i mean if you can of course, .. do a tutorial about "unit tests" in a React app, and deploy using "Github actions - CI/CD"... in AWS, or any other cloud service you prefer....
    I'm sure it will help lots of Devs out there, ...and also because these days, thats very important requirement that companies are looking for...
    And again thank you very much for always share great content..

  • @sojocjohny
    @sojocjohny Рік тому +1

    Hi, can you do a video about making a component for image cropping, resizing and converting them to base64 or File or Blob as per requirement in react typescript... That would be helpful.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Рік тому

      Great suggestion! While not in React, I did do some of that in my TinyPNG clone with Vanilla JS: ua-cam.com/video/jEjo9UytpIc/v-deo.html

  • @karthikam6395
    @karthikam6395 Рік тому

    Thanks!

  • @aziskgarion378
    @aziskgarion378 3 місяці тому

    That's a crisp font, what font is it I wonder.

  • @Victor-wh9bs
    @Victor-wh9bs Рік тому

    Great explanation

  • @jaymonserrat5982
    @jaymonserrat5982 Рік тому

    You kind of look and sound like Aberama Gold from Peaky Blinders. Very cool 😂

  • @kakhabervk9405
    @kakhabervk9405 Рік тому

    I first of all thank for these videos. Today I searched maybe here is react-hook-form it meet me on one project and I think this hook is iteresting not nonly for me. sorry my not so english spelling.

  • @imam_robani
    @imam_robani Рік тому

    Cool !
    I think you forgot to explain the console.log process

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Рік тому

      I left it in there so you could see how it works - but I did not go back to show it. For every letter you type, you will see the timeout is cleared - until you stop typing and then you will allow the final timeout to complete :)

  • @studybelief
    @studybelief 6 місяців тому

    Hi Dave, I'm wondering if I should use the debounce function written in vanilla JS for the setValue. Does it matter?
    `function debounce(fn, delay) {
    let timer;
    return function (...args) {
    clearTimeout(timer);
    timer = setTimeout(() => {
    fn(...args);
    }, delay);
    };
    }`

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  6 місяців тому +1

      Debouncing a search input is a good idea. There is also a React-ful way to do it.

    • @studybelief
      @studybelief 6 місяців тому

      @@DaveGrayTeachesCode Thank you sir 😊

  • @lebronjaimeslannister
    @lebronjaimeslannister Рік тому

    Hi Dave,
    after watched the previous debounce tutorial I tried to use that vanilla way in a Next.js project,
    turns out it worked fine, am I missing any potential problem?
    or creating the custom hook for debounce is generally better for a react app.
    Thank you!

  • @big-jo89
    @big-jo89 Рік тому

    can we just use the de-bounce as a helper function, is there any benefits from using a hook rather than just a normal function

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Рік тому +1

      That's essentially what the hook delivers. You could really ask that question about any hook that provides a function. That said, if you will use other hooks to create your function, you need to create a hook following the rules of React. We could go down a rabbit hole asking if we really need any of React's features or rules at all because it is just Javascript - but when using React, I try to do things in a React-ful way.

  • @michaelscofield2469
    @michaelscofield2469 Рік тому +1

    content idea: infinity scroll but not down, to top like whatsapp like slack, when we scroll top fetch the data and show

  • @Web-Himansu
    @Web-Himansu Рік тому

    sir can I start WebDevelopment skill with MDN Documentation or any programming language Documentation.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Рік тому

      I think MDN provides the best HTML, CSS, and JavaScript documentation. It can be a little technical at times but it is detailed. w3Schools.com might provide easier to read documentation when starting out - but MDN is the source of truth.

    • @Web-Himansu
      @Web-Himansu Рік тому

      @@DaveGrayTeachesCode your advice and directions for me . I never forget 💕 💕 💕 💕 💕 💕 💕 💕 you and your guide to path that i want in my life and my goals. God always with you sir. I never forget "STRIVING FOR PROGRESS, NOT PERFECTION".

    • @Web-Himansu
      @Web-Himansu Рік тому

      @@DaveGrayTeachesCode sir how much time to learn javascript from MDN.

  • @DazzyDude00
    @DazzyDude00 Рік тому

    How would you use this without SWR? I tried using axios, useFetch, and there seems to be limitation to WikiPedia API, search value is required and on initial load the input is empty and the error shows up: 'The "gsrsearch" parameter must be set.'

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Рік тому +1

      No issue with the Wikipedia API. You can prevent sending a request until you have input - and debounce can be applied to any type of input and request - not just SWR.
      Here is a Vanilla JS tutorial I have on debounce: ua-cam.com/video/yBFHwJgqLD4/v-deo.html
      You can apply this to fetch, axios, and anything else you use to send requests.

  • @belkocik
    @belkocik Рік тому

    React Debounce Search Input with react query next? :D

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Рік тому

      Maybe not next, but I could do that sometime. Debounce would work the same. The only difference would be how to apply it in RQ vs SWR.

  • @dainsleif3122
    @dainsleif3122 Рік тому

    whats with all the else if's ? friendly tip. don't use else if's its very difficult to read.
    this would be better
    if(seomething) => return 'something'
    if(something_else) => return something else
    ]

  • @Abdullab_Niaz-ri1sc
    @Abdullab_Niaz-ri1sc Рік тому

    Sir, please recommend me MERN Stack master level course