Make a Search Bar with React (with API Calls) | Beginners Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ก.พ. 2023
  • Through this tutorial, learn how to make a search bar component using React. This beginner project covers ReactJS, functional components, props, state, API calls using fetch, HTML, and CSS.
    Are you looking to build a powerful search bar in React that can retrieve data from any API? Then look no further! In this comprehensive tutorial, we'll show you how to create a search bar component that connects to an API and fetches data dynamically using React.
    Throughout the tutorial, we'll cover the basics of React and demonstrate how to use React hooks and state management to create a search bar that dynamically updates as you type.
    By the end of the tutorial, you'll have a fully functional and professional-looking search bar component that can be used in any type of web application, including e-commerce, social media, or search engines. So don't wait any longer, start building your own search bar in React today!
    🚨 Break into a software dev career with this free course from CourseCareers! - coursecareers.com/a/TechStack... 🚨
    Discord - / discord
    Subscribe - / @code_complete
    ☕ Donate to support the channel! - www.buymeacoffee.com/CodeComp...
    -- 🌟 Useful Tools and Software 🌟 --
    🌐 10% off domains at Domain.com (use code DOMAIN10) - domain.mno8.net/CodeComplete
    ☁️ FREE $100 for server hosting on Linode - linode.gvw92c.net/CodeComplete
    📚 30% off annual Skillshare membership (use code annual30aff) - skillshare.eqcm.net/CodeComplete
    -- 🔗 Links 🔗 --
    💻 Code - github.com/CodeCompleteYT/rea...
    DISCLAIMER: Some of the links in the description are affiliate links. The channel will receive a small commission from any sales from these links, but there is no extra charge to you. Thanks for supporting the channel so I can keep making these free tutorials!

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

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

    Have questions or feedback? Head over to our Discord server! discord.gg/TWBtv5an7N
    Solve advanced programming challenges and become an expert software engineer with CodeCrafters! 40% discount on your membership - app.codecrafters.io/join?via=CodeCompleteYT

  • @freddie4818
    @freddie4818 ปีที่แล้ว +9

    This was so great. Easy and clear to follow without being too slow. Thank you!

  • @vladkara
    @vladkara ปีที่แล้ว +3

    Awesome! Short and very clear!

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

    Clicked in this video accidentally, REALLY an AWESOME tutorial mate

  • @abhishekraisycs514
    @abhishekraisycs514 ปีที่แล้ว +8

    Great tutorial mate! Made this project at 12am at night while waiting for champions league clash between bayern vs psg.

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

      Thanks man! Hope your team won 😃

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

    Very helpful! Thanks! 😀

  • @codewar534
    @codewar534 ปีที่แล้ว +8

    Awesome tutorial man! Helped me a lot to learn api in react js!🔥

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

    My god this is absolute life saver this video! I was struggling hard understanding the concepts and you explained it so well! Definitely gained a sub from me!

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

    This was very helpful. Thank you very much.

  • @Anubis10110
    @Anubis10110 9 หลายเดือนก่อน +3

    You can add debounce to save network calls… thanks for you effort

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

    Loved you contents, thanks man

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

    I have been banging my head several times as a backend developer trying to whip up simple FE interfaces. Your video is the first that gets me somewhere. At last. Your patient explanations but some queries to ChatGPT are making me progress a little. Thanks a lot.

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

      Glad you found the video useful!

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

    Helpful! Thanks so much!

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

    very well presented, thanks.

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

    Hey! Thank you so much for sharing your knowledge with us. This video was a big help for me.

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

    Thx bro, that helped me a lot!!!

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

    Very helpful, thank you!

  • @minimunch1971
    @minimunch1971 23 วันที่ผ่านมา

    This tutorial is great!! Thank you for explaining what each line of code is for, I learned a lot!

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

    Thank You so much for this wonderful lecture ☺️

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

    Brilliant video and it has helped me a great deal.

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

    this helps a lot thanks man

  • @AjayKasthala
    @AjayKasthala ปีที่แล้ว +3

    Need more Tutorials like these
    Kudos to you

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

    That was great tutorial ❤

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

    thanks sir its wonderful tutorial for learning anything

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

    thanks for this tutorial, very helpfull!!!

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

    Wonderful tutorial man

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

    just what i was looking for, thank you very much, i was trying to make my first react project using api but could not find relevant explanation.

  • @MaxMov-sp8hr
    @MaxMov-sp8hr ปีที่แล้ว +1

    Nice! Simple & Clear! ☀

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

    Excellent video. The only criticism I have is the contrast is insufficient for those with low vision. I realize the focus is on the code, but the UI determines its accessibility. Please keep that in mind for future projects. Thanks!

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

    super explanation bro. more videos we need

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

    I learned something new thanks

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

    thank you!!

  • @jagadishdasari9120
    @jagadishdasari9120 ปีที่แล้ว +5

    Wonderful tutorial. Please do a common implementation across various JS flavors like Angular/React/Vue/etc to show the variance…👏

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

      I feel like you really get it in react you should also get it in other frameworks. Concept is same.

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

    thank you very much

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

    shanadar Jabardast Jindabad bhai ek dum super

  • @felixfale964
    @felixfale964 ปีที่แล้ว +2

    Thank you brother, your tutorial really helped me

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

    Great tutorial! I was wondering if we should be able to fetch results in the useEffect hook.

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

      Great idea! That way the data only needs to be fetched once

  • @farid9323
    @farid9323 10 หลายเดือนก่อน +3

    Helpful tutorial. In production apps, you'd need debouncing. Otherwise, you'd be calling the API on every key stroke.

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

    this is so helpful i was wondering how will I fetch multiple endpoint

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

    thank you

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

    Perfect tuto.... I'm from DR Congo and I wish all the best dear

  • @kishorek4319
    @kishorek4319 ปีที่แล้ว +3

    Make More Useful tutorial like this.!! Iam ready to learn More from you bro..😍💜

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

    Question. How do you clear the search bar once you click on something? Great tutorial! Thanks!

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

    Superb and simple project

  • @bykeride2-dw1ly
    @bykeride2-dw1ly หลายเดือนก่อน

    Just one word.... , superb.... Explanation

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

    super👌 . please make image editor with features having color change of image(also gradient color and monochrome) compress the image to reduce size , image characterisation by their types (png, jpg... ect)

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

    you have gained a subscriber!

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

    Great video.
    It would be a much better user experience if you use text wrapping if you have the browser open on the side. And a bonus if you close the explorer on the side.
    Sometimes it's difficult to see what you typed

  • @kakun7238
    @kakun7238 ปีที่แล้ว +3

    one for the infinite scrolling in this select too

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

      Thanks for the great suggestion!

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

    yeah its looking good and understandable can you please explain the hole thing what you have done ? like not technical tell me in 5lines

  • @HaroonKhan-ov4ru
    @HaroonKhan-ov4ru 6 หลายเดือนก่อน

    Is there a way to have this feature search through two collections in a data base?

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

    Nice tutorial! You haven't used async in fetch data funtion, then how it can be used as for performing async function fetching data?

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

      You can use async/await which is the new way of doing things or you can use promise chaining using .then() which is slightly older

  • @segu_.
    @segu_. 4 หลายเดือนก่อน +2

    good tutorial!
    wouldnt make more sense to fetch just one time the api and then run a filter method when input changes?
    thanks!

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

      Good question! That makes sense when we have < 100 items in our database for example but if we had 100,000 items for example, it would take a lot of bandwidth and time to first fetch all that data

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

      @@Code_Complete true!

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

    Excelent tutorial, I had one question, Insted of showing the results on the same page can we use react router to redirect to another page and show the results there?

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

      Yes. You could use global state with the router.

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

    Hey buddy great tutorial. I had a question that inside fetchData function i am not able to change fetch to using hook useEffect - which is the new way. The error we get is - Hooks can only be called inside of a body of a function component. Basically they are asking us to use hooks only at the top level of react function.
    So any idea how we implement onChange but with hooks and not just fetch

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

      make sure the useEffect comes before any codeblock like if(){}

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

    will it return closest matching word? for example if i type "food" will it be able to detect the word "foods"

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

    Can i use different api from another website like google books api

  • @KuldeepSingh-jg9xz
    @KuldeepSingh-jg9xz 12 วันที่ผ่านมา

    how do i set the value selected under SearchResults back to Searchbox . Can you also share that ?

  • @user-dj4qx7hh4i
    @user-dj4qx7hh4i 3 หลายเดือนก่อน

    why didn't you use the useEffect for dependency?

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

    Hello, when i create a build file with vite. The routing system does not work like its work fine inside website navigation but when I write URL by myself it say GET no request found

  • @sharath_jonnala
    @sharath_jonnala 5 หลายเดือนก่อน +2

    Can you please make a video how to implement binary search in this?

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

      By the way this is a nice video

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

      Oh that’s an interesting question! Could you share more details about what you would like in the discord server linked in the channel page? We can discuss a possible solution there

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

    Similar answer I got from Chatgpt, but better explained.

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

    would be greate if you can cover FE interviews system design questions on this channel
    Subscribed!!

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

      Thats a great idea! Will look into it 👍

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

    Hi I have a project the users table which I have to create a search bar and filtering the users but the API my partner back end did it now I become dizzy what should do? can you help me?

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

    Can you make another video same as this but the API call using redux and show a list whatever inside in API.

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

    Hi please make video how to integrated otika or stisla bootstrap template to reactjs
    Because iam getting stuck sidebar not working when navigate to other page using react-router-dom

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

    At 15:50, I didn't understand how you evaluated those variables in the return statement as Boolean ?

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

      In JS if a value is "falsy" i.e. null, undefined, 0, "", etc. it is treated as false. In that line I chained up multiple values which could be truthy or falsy using && operators

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

      @@Code_Complete thanks for your reply. Actually I was unaware that the filter function filters a particular element of the array based on the boolean returned from its callback.

  • @user-ud1qk3yi7m
    @user-ud1qk3yi7m 3 หลายเดือนก่อน

    short and descriptive

  • @nics.nvrlnd
    @nics.nvrlnd ปีที่แล้ว +1

    is it okay to use debounce?

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

      Yup that would be great! I wanted to include that in this tutorial but thought it might be a bit too much for a beginners tutorial

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

      ​@@Code_Complete But still debouncing will still result in more api calls, one solution i can think of is caching the data fetched from the api and then filtering the data in the frontend itself to reduce api calls. Is it right? Wanted to know what production level apps use

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

    How to make delay between requests when typing, without delay it would be like dos attack to server😂 Very helpful video, thank you, hope for answer)
    Edit: you can use debounce method

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

    Can you tell me what should i do to automatically hide the search list if I scroll the page?

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

      use the propertie of your input html element, onFocus to show the suggestion and the items and onBlur to hide them

  • @mzeren4713
    @mzeren4713 ปีที่แล้ว +3

    it works when it is lowercase but it deosnt work when it will be uppercase

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

      Good catch, it should be user.name.toLowerCase().includes(value.toLowerCase())

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

    what if i have my own API, im getting an error 'products.filter is not a function'

    • @Code_Complete
      @Code_Complete  ปีที่แล้ว +3

      You should try logging out what products is. This likely means its not an array and could be an object or undefined

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

    What is the difference in creating React application using npx create react app or using vite creat react app?

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

      Both vite and create-react-app accomplish the same goal of starting a react project quickly. Vite is just better because it is more customizable and has a smaller bundle size

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

      @@Code_Complete I'm asking what is the difference we will have while coding.
      This is okay that we will have bundler as Vite NOT webpack.
      And what are all major difference we will have using vite?

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

    Very nice tutorial, can you tell us how you integrate Google or Bing Search API? In react app thanks

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

    Use typehead

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

    This does an API request on EACH change? Isn't that a HECK of a lot of API calls?

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

    12:29

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

    The video is great but if word wrap was on it will be easier to go with it.

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

      Good point, thanks! Will use it in my future videos

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

    if you didn't remember how to reopen that all then
    open terminal
    1) cd react-search-bar
    2) npm install
    3) npm run dev
    *** for those who closed the vscode and unable to open the whole website or local host***

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

    lazy me didn't make alot component to make the react app look simpler and more organized

  • @AvinashYede-ck2cs
    @AvinashYede-ck2cs ปีที่แล้ว +1

    can you make tutorial on redux

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

    its great but make video of the same project by using next 13 app router.

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

    Use filter on server side bro.. dont take all the datas from API just to filter it in front-end..

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

    Why not make it on click? When you're working on a large project with a lot of data, you want to use a button-enabled search.

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

    Hello! Thank you very much for a very useful lesson! How to make it so that if we select Leanne Graham as a result, it will show us "username" and "email".
    For example:
    Leanne Graham
    Bret
    Sincereapril.biz

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

    isn't this going to skyrocket your hosting bill by making an api request in every key stroke?

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

      You would need to debounce the input.

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

      @@farid9323 can you please explain a bit what do you mean with "debounce"?

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

      ​@@ilirbajrami2902basically debouncing delays the function call so instead of calling the api on every keystroke, you can set the delay to maybe 400ms so when the user stops typing or the keystrokes are delayed for more than 400ms then only the api would be called

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

      But still this will still result in more api calls, one solution i can think of is caching the data fetched from the api and then filtering the data in the frontend itself to reduce api calls

  • @user-wg9nv5ms9m
    @user-wg9nv5ms9m 3 หลายเดือนก่อน

    add something

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

    man use time staps, so whoever wants can chose the part they are looking for.

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

    No need to create state in app man

  • @Omar-gr7km
    @Omar-gr7km 10 หลายเดือนก่อน +10

    That poor API. Getting called with every letter typed or deleted 🤣

    • @Omar-gr7km
      @Omar-gr7km 10 หลายเดือนก่อน +2

      Also, its strongly advised that you don't use map id as the key. In this example, each json item has an id, so you should use that.

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

      What should you do instead?

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

      Why so much prop drilling, is it a standard practice?

    • @rahulnikam1279
      @rahulnikam1279 4 หลายเดือนก่อน +15

      As he is teaching for beginners you should not laugh... and don't try to be very cool in comments... you don't might even know the solution for that issue...
      Ans for this issue is: You can implement debounce on frontend and cache on server side! Study more about debounce ❤

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

      Api crying

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

    This is trash code. Each letter a sent to API? no one use alert() and maybe instead of input to alert you should fulfill the form? ahhh that was to hard i got it

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

    wrong method.

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

      Why don’t you teach the correct method ?

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

    To the point. Amazing Job
    Looking Forward for your new videos.
    Thanks for this

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

    Muchas gracias muy bien explicado gracias