Learn Custom Hooks In 10 Minutes

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

КОМЕНТАРІ • 194

  • @brian-lau
    @brian-lau 4 роки тому +134

    damm, i am hooked now

  • @MagiCityProductions
    @MagiCityProductions 2 роки тому +5

    You have the best tutorials. You never add a bunch of unnecessary commentary and for that I thank you.

  • @krisnarusdiono1304
    @krisnarusdiono1304 2 роки тому +10

    i have finished all this react hook series in this channel, literally worth every seconds. Thanks Kyle

  • @yanivgk
    @yanivgk 4 роки тому +69

    I'm usually not using custom-hooks because I lack the imagination where to use them, and video just gave me 2 great ideas, thanks ! :)
    It would be great if you could do more videos regarding different common custom-hooks like these ones.

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

      Yup, I think we don't have the coders' minds YET!!! or maybe we need to throw ourselves into the fire of a working environment to get creative and find use cases of various programming concepts.

  • @FaysalBDev
    @FaysalBDev 2 роки тому +2

    this video is so underrated, it should have like a billion likes. thank you

  • @wendylee5498
    @wendylee5498 3 роки тому +3

    It's worth taking note that the views counts for this series dropped from 216,154 views (1st video) to 42,597 views (last video), maybe means there 's a learning curve; and I am proud that I watched all and code along. Great work Kyle!!!

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

    Can someone please explain: why assign a function in useState will reduce the call of localstorage, like he said in 5:20, "only call this once when first time rendering the component, not everytime render". I mean this function in useState still returns the result of function savedValue, so why not write like const [value, setValue] = useState(savedValue(key, initialValue)) ? Can anyone explain it?

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

      I don't know if you already found your answer, but just in case...
      When using a function as initial value for useState, we need to practice "CURRYING" or wrapping function executions in another function, like this:
      useState(( ) => someFunc( ))
      as opposed to just: useState(someFunc( )).
      This way, someFunc doesn't get called unnecessarily every re-render. It's not noticeable on small apps but treat it as an optimization with the way useState hook works. In the video, the data from local storage is only read at the initial component render.
      EDIT: Try putting a console.log( ) on the function and compare. The one with no currying will show the log every keystroke.

  • @ינוןאלבז-כ1ז
    @ינוןאלבז-כ1ז 2 роки тому +3

    You're really simplifying the web for me

  • @samartajshaikh2601
    @samartajshaikh2601 2 роки тому +1

    The way you explain it, i am in awe of it.

  • @dannnnydannnn5201
    @dannnnydannnn5201 3 роки тому +7

    Great series. You really helped me figure out the difference between the different types of react hooks. I was not having the easiest time trying to figure it out looking through other people's code. Thanks man. Keep the videos coming. You're great at what you do!

  • @deepanjii2009
    @deepanjii2009 4 роки тому +7

    Wow man. You really have made the web simplified for us to build our project. Awesome content as always👏

  • @kamelowy
    @kamelowy 2 роки тому +2

    useLocalStorage hook should be implemented in React by default, it makes the operations on local storage so clean i can't imagine doing it the "default" way again. Thanks for another great tutorial! :)

  • @aubidanaalwa4161
    @aubidanaalwa4161 3 роки тому +2

    you are one of the best that explains, thanks a lot for all the useful information

  • @alan-k1n2r
    @alan-k1n2r 4 роки тому +30

    React and hooks are so freaking fun. I just got my first job as dev and first task was creating a frontend all with hooks, apollo graphql, typescrypt and redux. When you figure it out you can play around with data really nicely. PS great channel

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

    Thanks!

  • @yashdefy
    @yashdefy 2 роки тому

    I am "hooked" to this channel..

  • @madhusudhan4001
    @madhusudhan4001 4 роки тому

    i have three letters for this video WTF ---- hands-down best explanation of custom hooks... thanks Kyle.

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

    Thanks so much for these videos, they are very concise and easy to follow.

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

    i use redux toolkit and it helps me a lot. but really thanks for the video. we love u

  • @Kilopillz
    @Kilopillz 3 роки тому +1

    Please keep this up this is really great. I just finished your entire hooks Playlist. Thank you😊

  • @BeCurieUs
    @BeCurieUs 4 роки тому

    This example is perfect for me! I was creating a React project to manage Arkham Horror LCG stuff, and just had to saved in a big ol state. But for saving games serverlessly, local storage was gonna be the way I handled it. This idea will meld in nicely with saving my data, woot!

  • @faris.abuali
    @faris.abuali 2 роки тому +1

    Thanks for simplifying react for us!

  • @bohdanromanovich4912
    @bohdanromanovich4912 3 роки тому +1

    Your video's is awesome. It's so simple to understand what you are saying! Thank you so much!

  • @titlisarkar278
    @titlisarkar278 4 роки тому +1

    Thanks Kyle... These videos are really helpful for beginners.

  • @undisputedlegend7568
    @undisputedlegend7568 15 днів тому

    Thanks bro, You're a lifesaver 😍🤜🏻🤛🏻

  • @oskarmarkin5674
    @oskarmarkin5674 4 роки тому +17

    UA-cam should make a two like button only for your channel because I would give you two likes

  • @מיכלדרור-דשת
    @מיכלדרור-דשת 2 роки тому

    best explanation ever!! thank you

  • @amiturfnd
    @amiturfnd 4 роки тому +2

    Thanks a lot for this video. learnt something new today :)

  • @muhammadzeeshan07
    @muhammadzeeshan07 4 роки тому

    Superb kyle, every thing is clear

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

    Great tutorial! Thank you for the explanation! 💛

  • @saurabhma123
    @saurabhma123 3 роки тому

    Greatly explained the concept!

  • @VishalSharma-rn7mt
    @VishalSharma-rn7mt 4 роки тому

    Awesome explanation, genius guy

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

    really great tut. thanks dude

  • @parasmaniseth7873
    @parasmaniseth7873 4 роки тому

    Before knowing this...I also use to the same thing....saving things in local storage....today he made this a react custom hook
    Kyle do knows how to use his tools appropriately and in efficient way

  • @MaxProgramming
    @MaxProgramming 4 роки тому +1

    Thank you! This is very much simplified to me!

  • @gaatutube
    @gaatutube 3 роки тому

    Thanks for the great series on react hooks. Will definitely have to go through it a 2nd time to let all the details sink in. But I have good overview of it now.

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

    Can someone explain what he does starting 5:02? "And now we what we can do is use a function version...". As opposed to what? Does writing an explicit return statement make it a "function version"?

  • @moiserwibutso4899
    @moiserwibutso4899 2 роки тому

    Thanks for this great tutorial.

  • @akashdevgan
    @akashdevgan 3 роки тому +2

    One question, why will initialValue be a function?

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

    Imagine getting hearted by one of the best teachers on the internet

  • @basiccodingwithadam8125
    @basiccodingwithadam8125 4 роки тому

    Great little video, as usual, Kyle.

  • @rohandevaki4349
    @rohandevaki4349 4 роки тому

    at 1:19, what is the alternative for localstorage?, can we use useContext or redux for global storage, or even though if we use useContext or redux, the input value will become empty?

  • @diegoburlandotheinformal1217
    @diegoburlandotheinformal1217 3 роки тому

    Good job man!

  • @snaplu4683
    @snaplu4683 4 роки тому

    great tutorial series, thank you so much

  • @juliangzr4998
    @juliangzr4998 3 роки тому

    Thank you very much! great video

  • @Neha-sw6ky
    @Neha-sw6ky 4 роки тому +5

    Amazing video. I'm in love with you!

  • @arunbm123
    @arunbm123 2 роки тому

    very nicely explained

  • @l.e.nichols9382
    @l.e.nichols9382 3 роки тому

    This is awesome, thanks so much.

  • @vinaykumar-sg7xd
    @vinaykumar-sg7xd 3 роки тому +2

    how can initialvalue be a function. i didn't get that part. can anyone explain please

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

    nice bro thanks for giving this video

  • @YRS24
    @YRS24 3 роки тому

    awesome learnt about local storage and hooks

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

    hello i have one question
    i want to use the usedispatch and useselector outside the function and class component. i have a helper.js in which i am trying to call the api by using redux saga for that i need to use usedispatch and then the response i want to get through useselector in same helper class. any idea how to achieve this

  • @krishnayele5639
    @krishnayele5639 4 роки тому

    liked it, loved it, just the thing I was looking for. Thanks very much.

  • @DeepakGupta-hj2dv
    @DeepakGupta-hj2dv 4 роки тому

    Great explanation kyle ..please make on one video Event loop

  • @piotrekjazz1287
    @piotrekjazz1287 2 роки тому +2

    5:20 I thought this is about simplifying tricky Custom Hooks, and not complicating them, so pointless

  • @liamcao-j6y
    @liamcao-j6y 2 роки тому

    thx already shared to Twitter

  • @orennkimg6851
    @orennkimg6851 4 роки тому +1

    someone can help me please ? i dont understand how the localStorage is updating because he didnt send the paramter of the name to the useLocalStorage hook but just constant paramaters ("name","") so how it works???

    • @azgexHQ
      @azgexHQ 4 роки тому +3

      Okay after spending more time than I would like to admit, I finally figured it out!
      Notice that UseLocalStorage hook is returning [value, setValue]. Then in App.js it is [name, setName]. Here "setName" is actually the "setValue" function being returned by useLocalStorage hook. Therefore, when is being used on the onChange event it's actually updating "value" inside the custom hook and not "name" in App.js.

    • @orennkimg6851
      @orennkimg6851 4 роки тому

      @@azgexHQ thank you bro ! very good explanation:)

  • @dmcshehan
    @dmcshehan 4 роки тому

    Thanks a lot for the video.

  • @anasalhariri5474
    @anasalhariri5474 2 роки тому

    Kyle, how do you get the localstorage in chrome to update when the state is changing? I had to refresh the localstorage to see the new value. Can you please help?

  • @Pareshbpatel
    @Pareshbpatel 2 роки тому

    Great Tutorial on Custom Hooks in React. Thanks, Kyle
    {2022-02-24}, {2022-08-02}, {2022-11-16}, {2023-06-28}

  • @SS-re8xb
    @SS-re8xb Рік тому

    Is "if(initialValue instanceof Function) return initialValue();" necessary? Because if using a console.log() to print out whether it's true or false, we'd always get "false". So, what's the reason to use this line of code?

  • @manibarathi08
    @manibarathi08 3 роки тому

    You can even add a deleteItem function inside useLocalStorage to delete the item if the user needs to

  • @zlackbiro
    @zlackbiro 4 роки тому +1

    Now, why not to bring this to another level? build your custom hook useStateStore, then create useReducer inside, import store hook into your components and voila, you have global store like Redux. Also, you can privide that store using context api... :)

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

    amazing, thanks

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

    Can some1 explain to me why using a function in useState can help reduce the call on localstorage ?😊

  • @boses5320
    @boses5320 2 роки тому

    This was a great example... However if this example would help to stay login in after refreshing ..would be great

  • @kikiken4287
    @kikiken4287 2 роки тому

    Thanks for the good video!
    But I think your useTimeout function should be like something like below.
    export function useTimeOut(callback, delay, dependency) {
    const callbackRef = useRef();
    const timeOutRef = useRef();
    useEffect(() => {
    console.log('callback update');
    callbackRef.current = callback;
    }, [...dependency]);
    ...
    }
    because like you mentioned, callback without 'useCallback' is different always.

  • @nahida4444
    @nahida4444 2 роки тому

    Hey, a question, does a hook persist and share the state through multiple component, like context-provider works?

  • @BharatSingh-zk8lx
    @BharatSingh-zk8lx 2 роки тому

    this would definitely be helpful in react native
    😀

    • @priyankaroberts1093
      @priyankaroberts1093 2 роки тому

      Hey Bharat
      Have you built any react projects recently? Are you open to internship/job opportunities in software development ?

  • @MohitKumar-tn1cf
    @MohitKumar-tn1cf 3 роки тому

    Hi kyle, i'm getting an error like as ReferenceError: localStorage is not defined, when doing as same as you do. please help

    • @MohitKumar-tn1cf
      @MohitKumar-tn1cf 3 роки тому

      Oops i understand that, Am using Next JS tht why i'm getting an error bcoz of localStorage is not the part of server side, its is client side. thanks

  • @syedalimehdi-english
    @syedalimehdi-english 3 роки тому

    I don't understand, why don't we use useRef instead of useState?
    We could prevent un necessary re-renders right?

    • @kinstar
      @kinstar 3 роки тому

      He used usestate so he could log and show the input changing on each keystroke, he needs the re render for that

  • @ernestomotta5178
    @ernestomotta5178 4 роки тому

    Awesome, thank you

  • @riyajha6500
    @riyajha6500 4 роки тому

    thanks, sir for such awesome video, if you possible please make some videos on react recoil.

  • @PastaInformatyki
    @PastaInformatyki 4 роки тому +3

    In getSavedValue function: "if (savedValue) return savedValue" What if savedValue is false or 0 or an empty string? Shouldn't it be like: "if (savedValue !== null) return savedValue" or am i mistaken?

  • @tomermatmon
    @tomermatmon 4 роки тому

    This is great!

  • @kefistefi
    @kefistefi 2 роки тому

    Is there a way to change the key somehow, since I would love to have mutliple keys for every users that let's say loggs into my page.

  • @EJIqpEP
    @EJIqpEP 4 роки тому

    Hi Kyle, I really like your videos and the quality of the image. What camera are you using? Thanks!

    • @WebDevSimplified
      @WebDevSimplified  4 роки тому

      It is a logitech brio shooting in 1080p

    • @EJIqpEP
      @EJIqpEP 4 роки тому

      @@WebDevSimplified Thanks a lot!

  • @caesarbala
    @caesarbala 2 роки тому

    so custom hooks combination of function and component we take argument and return / without return . also we can useEffect within it .

  • @mr-moses-01
    @mr-moses-01 2 роки тому +1

    Dude how are you making your hair like that every day :D

  • @ziyadkader6767
    @ziyadkader6767 4 роки тому

    I am waiting for the MERN video ! :)

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

    Can i say custome hooks have the same purpose like HOC in class component.

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

      render props and hoc do the same kind of thing i guess

  • @OwaisAthar1
    @OwaisAthar1 2 роки тому

    Great ✨

  • @Human_Evolution-
    @Human_Evolution- 3 роки тому +8

    So lost. I cannot follow this video. Does anyone know of something even easier than this? I am like 10 hours into these and I feel like I know nothing.

    • @Viv-m8j
      @Viv-m8j 8 місяців тому

      Same here

    • @Human_Evolution-
      @Human_Evolution- 8 місяців тому

      @@Viv-m8j been a paid dev for over a year now. Still confused lol

  • @rohinchopra9812
    @rohinchopra9812 3 роки тому

    Even though how simple the last hook was it can be pretty handy in debugging stuff

    • @priyankaroberts1093
      @priyankaroberts1093 2 роки тому

      Hey Rohin
      Have you been working on any react projects currently? Are you open to internship/job opportunities in software development ?

  • @SumitKumar-bu3yn
    @SumitKumar-bu3yn Рік тому

    Thank you

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

    whats the configuration of your computer?

  • @iurii7752
    @iurii7752 4 роки тому

    Great, thank you :)

  • @shuuheihisagi3148
    @shuuheihisagi3148 4 роки тому

    Hey, thanks again for another video! Can you make on related to wherr to store jwt on the client side?

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

    just a little improvement, for the the custom hook we can use named-parameters, in that way the order of the parameters does not matter.

  • @eyotajr
    @eyotajr 4 роки тому

    when you type localstorate it get hightliged, what extension do that for you ?

  • @muonx9649
    @muonx9649 3 роки тому

    It just works!

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

    I ate these fucking hooks bcz of you, the great Kyle

  • @donnonixon
    @donnonixon 2 роки тому

    Please my custom hooks returns error usewindowsize is not a function

    • @a-roh5039
      @a-roh5039 2 роки тому

      Use Google to debug

  • @rogerjohn7786
    @rogerjohn7786 4 роки тому

    Hi Kyle please make a video on Instant search filter like youtube on react.

  • @MrXperx
    @MrXperx 3 роки тому

    Mind blow video

  • @satindersingh9671
    @satindersingh9671 4 роки тому

    You are the best

  • @abdullahawisimulaha
    @abdullahawisimulaha 4 роки тому

    Why to create useUpdateLogger if you just can write console.log(value)?

  • @randyfix3546
    @randyfix3546 3 роки тому

    Why on the useEffect does React complain about ' key ' being a missing dependency? I've seen this in a couple tutorials now, has something changed with React?

  • @ВадимАлекс-щ6ъ
    @ВадимАлекс-щ6ъ Рік тому

    thanks!

  • @nzanontest7716
    @nzanontest7716 2 роки тому

    Hi guys, i still don't understand the use of the the callback function inside the useState in the localStorage exaple;
    can't we just write : useState(getSavedValue(key, initialValue);
    if someone can explain more i would appreciate it.

    • @a-roh5039
      @a-roh5039 2 роки тому

      Don't ask questions in UA-cam comments, people aren't actively checking to give assistance. Use Google to ask questions