React Debounce Search Input API Call | useDebounce React Hook

Поделиться
HTML-код
  • Опубликовано: 16 сен 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 26 дней назад +1

    Thank you, it was usefull❤❤❤❤

  • @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.

  • @hungnguyencanh5089
    @hungnguyencanh5089 Год назад +1

    Thanks, Dave

  • @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!

  • @7doors847
    @7doors847 Год назад +1

    Very nice Dave!!👌

  • @s3interdev
    @s3interdev Год назад +1

    Thank you Dave, very helpful.

  • @TravinskiyVladislav
    @TravinskiyVladislav Год назад +1

    Thank you, Dave

  • @adityakunwar1524
    @adityakunwar1524 Год назад

    was waiting for this video for a long time

  • @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

  • @hardwired89
    @hardwired89 Год назад

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

  • @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..

  • @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

  • @sakibcoder
    @sakibcoder Год назад

    very clean intructions💯

  • @youssefkarfouh3084
    @youssefkarfouh3084 6 месяцев назад

    thank you so much dave

  • @rounakmukherjee9540
    @rounakmukherjee9540 Год назад

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

  • @baconovertures1675
    @baconovertures1675 Год назад

    Thanks 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!

  • @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.

  • @aziskgarion378
    @aziskgarion378 3 месяца назад

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

  • @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: ruclips.net/video/jEjo9UytpIc/видео.html

  • @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 :)

  • @The.mohisa
    @The.mohisa Год назад

    thanke you that's really helpful

  • @karthikam6395
    @karthikam6395 Год назад

    Thanks!

  • @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

  • @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 😊

  • @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.

  • @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: ruclips.net/video/yBFHwJgqLD4/видео.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.

  • @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!

  • @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.

  • @Victor-wh9bs
    @Victor-wh9bs Год назад

    Great explanation

  • @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