Learn Custom Hooks In 10 Minutes

🚨 IMPORTANT:
Full React Course: courses.webdevsimplified.com/...
In this video I cover everything you need to know about creating your own custom hooks. I go over all the main use cases for custom hooks as well as many common mistakes that developers make when creating custom hooks. In this video I will cover two different examples of how custom hooks can best be used. This is part of a series of React videos where I cover all the important hooks in React.
📚 Materials/References:
Custom Hooks Blog Article: blog.webdevsimplified.com/201...
React Hooks Playlist: • React Hooks
🧠 Concepts Covered:
- How to use custom hooks in React
- How to create custom hooks in React
- Best practices for custom hooks in React
🌎 Find Me Here:
My Blog: blog.webdevsimplified.com
My Courses: courses.webdevsimplified.com
Patreon: / webdevsimplified
Twitter: / devsimplified
Discord: / discord
GitHub: github.com/WebDevSimplified
CodePen: codepen.io/WebDevSimplified
#ReactJs #WDS #CustomHooks

Пікірлер: 188

  • @brian-lau
    @brian-lau3 жыл бұрын

    damm, i am hooked now

  • @lilspelunker5613

    @lilspelunker5613

    3 жыл бұрын

    get out

  • @anasaijaz7802

    @anasaijaz7802

    2 жыл бұрын

    what are yuo 14?

  • @mouadrimwind8839

    @mouadrimwind8839

    2 жыл бұрын

    I see what you did there

  • @Kilopillz

    @Kilopillz

    2 жыл бұрын

    Ahhhaha I love the pun😂

  • @l4webdesign186

    @l4webdesign186

    2 жыл бұрын

    I like how you react to this vid

  • @krisnarusdiono1304
    @krisnarusdiono13042 жыл бұрын

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

  • @MagiCityProductions
    @MagiCityProductions Жыл бұрын

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

  • @dannnnydannnn5201
    @dannnnydannnn52013 жыл бұрын

    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
    @deepanjii20093 жыл бұрын

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

  • @yanivgoldstein3875
    @yanivgoldstein38753 жыл бұрын

    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

    9 ай бұрын

    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.

  • @Kilopillz
    @Kilopillz2 жыл бұрын

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

  • @samartajshaikh2601
    @samartajshaikh26012 жыл бұрын

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

  • @titlisarkar278
    @titlisarkar2783 жыл бұрын

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

  • @wendylee5498
    @wendylee54983 жыл бұрын

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

  • @gaatutube
    @gaatutube3 жыл бұрын

    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.

  • @NovaMenteMedia
    @NovaMenteMedia11 ай бұрын

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

  • @MaxProgramming
    @MaxProgramming3 жыл бұрын

    Thank you! This is very much simplified to me!

  • @bohdanromanovich4912
    @bohdanromanovich49122 жыл бұрын

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

  • @aubidanaalwa4161
    @aubidanaalwa41612 жыл бұрын

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

  • @user-mo3cw6go7c
    @user-mo3cw6go7c Жыл бұрын

    You're really simplifying the web for me

  • @amiturfnd
    @amiturfnd3 жыл бұрын

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

  • @saurabhma123
    @saurabhma1232 жыл бұрын

    Greatly explained the concept!

  • @faris.abuali
    @faris.abuali2 жыл бұрын

    Thanks for simplifying react for us!

  • @kostiantynkarzhanov9216
    @kostiantynkarzhanov921610 ай бұрын

    Great tutorial! Thank you for the explanation! 💛

  • @snaplu4683
    @snaplu46833 жыл бұрын

    great tutorial series, thank you so much

  • @faysal1991
    @faysal1991 Жыл бұрын

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

  • @krishnayele5639
    @krishnayele56393 жыл бұрын

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

  • @BeCurieUs
    @BeCurieUs3 жыл бұрын

    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!

  • @muhammadzeeshan07
    @muhammadzeeshan073 жыл бұрын

    Superb kyle, every thing is clear

  • @VishalSharma-rn7mt
    @VishalSharma-rn7mt3 жыл бұрын

    Awesome explanation, genius guy

  • @user-nu6ye5cm8r
    @user-nu6ye5cm8r Жыл бұрын

    best explanation ever!! thank you

  • @rohitborra2507
    @rohitborra25079 ай бұрын

    really great tut. thanks dude

  • @basiccodingwithadam8125
    @basiccodingwithadam81253 жыл бұрын

    Great little video, as usual, Kyle.

  • @moiserwibutso4899
    @moiserwibutso4899 Жыл бұрын

    Thanks for this great tutorial.

  • @juliangzr4998
    @juliangzr49983 жыл бұрын

    Thank you very much! great video

  • @l.e.nichols9382
    @l.e.nichols93822 жыл бұрын

    This is awesome, thanks so much.

  • @arunbm123
    @arunbm1232 жыл бұрын

    very nicely explained

  • @diegoburlandotheinformal1217
    @diegoburlandotheinformal12173 жыл бұрын

    Good job man!

  • @yashdefy
    @yashdefy2 жыл бұрын

    I am "hooked" to this channel..

  • @dmcshehan
    @dmcshehan3 жыл бұрын

    Thanks a lot for the video.

  • @oskarmarkin5674
    @oskarmarkin56743 жыл бұрын

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

  • @ernestomotta5178
    @ernestomotta51783 жыл бұрын

    Awesome, thank you

  • @DeepakGupta-hj2dv
    @DeepakGupta-hj2dv3 жыл бұрын

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

  • @kamelowy
    @kamelowy Жыл бұрын

    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! :)

  • @shuuheihisagi3148
    @shuuheihisagi31483 жыл бұрын

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

  • @Neha-sw6ky
    @Neha-sw6ky3 жыл бұрын

    Amazing video. I'm in love with you!

  • @omarbarra3456
    @omarbarra3456 Жыл бұрын

    amazing, thanks

  • @thivatutorials4040
    @thivatutorials40407 ай бұрын

    nice bro thanks for giving this video

  • @madhusudhan4001
    @madhusudhan40013 жыл бұрын

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

  • @tomermatmon
    @tomermatmon3 жыл бұрын

    This is great!

  • @YRS24
    @YRS243 жыл бұрын

    awesome learnt about local storage and hooks

  • @fkbey5756
    @fkbey5756 Жыл бұрын

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

  • @paccioti
    @paccioti3 жыл бұрын

    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

  • @abdullahawisimulaha

    @abdullahawisimulaha

    3 жыл бұрын

    Id love to have that kida job

  • @iurii7752
    @iurii77523 жыл бұрын

    Great, thank you :)

  • @williamgogo5313
    @williamgogo5313 Жыл бұрын

    thx already shared to Twitter

  • @SumitKumar-bu3yn
    @SumitKumar-bu3yn Жыл бұрын

    Thank you

  • @user-ef2pn4zc8f
    @user-ef2pn4zc8f Жыл бұрын

    thanks!

  • @DanteS-119
    @DanteS-119 Жыл бұрын

    This is great. ONE SUGGESTION: The input writing like that all the time to storage may NOT be good for performance. You should probably DEBOUNCE the input: that is do NOT write it immediately, maybe you can write it to the state in-memory immediately but to wait before writing to storage... This is especially something to keep in mind if you want to adapt this use case for API usage. I believe the only thing that you'd need to do is just set a lambda with `setTimeout` wrapped around the `localStorage.setItem(...)`, and then from the `useEffect` return a `clearTimeout` with the lambda passed in as a parameter. Because `setValue` within `useLocalStorage` (which is returned to the calling function which us using the hook `useLocalStorage`) is already based on the default React hook which will take care of setting the information to local memory. You already address the performance issues with /reading/ at 5:40 , as you are only reading when you fetch the INITIAL VALUE, which will attempt to fetch from local storage or just return whatever value was passed in to be the initial value; this in turn activates the hook for `useEffect` below that puts it into local storage. Elegant. Nice stuff.

  • @justinmlawrence
    @justinmlawrence3 жыл бұрын

    Awesome!

  • @riyajha6500
    @riyajha65003 жыл бұрын

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

  • @OwaisAthar1
    @OwaisAthar12 жыл бұрын

    Great ✨

  • @parasmaniseth7873
    @parasmaniseth78733 жыл бұрын

    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

  • @muonx9649
    @muonx96493 жыл бұрын

    It just works!

  • @nahida4444
    @nahida44442 жыл бұрын

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

  • @rohandevaki4349
    @rohandevaki43493 жыл бұрын

    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?

  • @sleepingUgly
    @sleepingUgly2 жыл бұрын

    TL;DR: "It's just going to work" Great video 🙌🏼

  • @anasalhariri5474
    @anasalhariri5474 Жыл бұрын

    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?

  • @ziyadkader6767
    @ziyadkader67673 жыл бұрын

    I am waiting for the MERN video ! :)

  • @MrXperx
    @MrXperx3 жыл бұрын

    Mind blow video

  • @EJIqpEP
    @EJIqpEP3 жыл бұрын

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

  • @WebDevSimplified

    @WebDevSimplified

    3 жыл бұрын

    It is a logitech brio shooting in 1080p

  • @EJIqpEP

    @EJIqpEP

    3 жыл бұрын

    @@WebDevSimplified Thanks a lot!

  • @manibarathi08
    @manibarathi083 жыл бұрын

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

  • @vinaykumar-sg7xd
    @vinaykumar-sg7xd2 жыл бұрын

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

  • @rogerjohn7786
    @rogerjohn77863 жыл бұрын

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

  • @satindersingh9671
    @satindersingh96713 жыл бұрын

    You are the best

  • @mateokks8531
    @mateokks8531 Жыл бұрын

    te quiero mucho, gracias

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

  • @akashdevgan
    @akashdevgan3 жыл бұрын

    One question, why will initialValue be a function?

  • @kikiken4287
    @kikiken4287 Жыл бұрын

    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.

  • @SS-re8xb
    @SS-re8xb7 ай бұрын

    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?

  • @ridl27
    @ridl273 жыл бұрын

    ty.

  • @amankaushik5833
    @amankaushik58333 жыл бұрын

    Really, really awesome video!! as always by the way I wanted to ask that can we make android apps in like plain javascript without using React Native and can we use js with C++ or python?Thanks!!

  • @prabhatchanchal

    @prabhatchanchal

    3 жыл бұрын

    I know one way to use js with python is "eel" but not don't know about C++ with js.

  • @fredhair

    @fredhair

    3 жыл бұрын

    Android supports c++ natively and has its own NDK but why you'd want to mix it with js im not sure. PWA is basically using js and c++ just the c++ is written by the browser vendor. Its all possible but the practicality of it will depend on the kind of software you want to write.

  • @amankaushik5833

    @amankaushik5833

    3 жыл бұрын

    @@fredhair hey there!! actually, I was thinking that it would be easier to make a user interface if we combine c++ with js, HTML, AND CSS maybe Node js would do it.

  • @boses5320
    @boses5320 Жыл бұрын

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

  • @PastaInformatyki
    @PastaInformatyki3 жыл бұрын

    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?

  • @bryceblazegamingyt9741
    @bryceblazegamingyt9741 Жыл бұрын

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

  • @willmakk
    @willmakk3 жыл бұрын

    love me some cutsom hooks

  • @ngocdangduc3772
    @ngocdangduc3772 Жыл бұрын

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

  • @caesarbala
    @caesarbala Жыл бұрын

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

  • @Kats0unam1
    @Kats0unam13 жыл бұрын

    Do you have a course with Hooks + Redux ?

  • @fatfooodie
    @fatfooodie3 жыл бұрын

    Hey viewers, comment your favorite custom hook that you think is very useful. For example, I use "useFormFields" and "useInput" in almost all my react projects.

  • @migueldomingos4570

    @migueldomingos4570

    3 жыл бұрын

    I use the ones you mentioned and I have started using a new one called use fetch to fetch data

  • @uprisingalpha2065
    @uprisingalpha20658 ай бұрын

    god damn good tho full skilled in this shit :D thx for ur video

  • @rohinchopra9812
    @rohinchopra98122 жыл бұрын

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

  • @priyankaroberts1093

    @priyankaroberts1093

    Жыл бұрын

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

  • @BharatSingh-zk8lx
    @BharatSingh-zk8lx Жыл бұрын

    this would definitely be helpful in react native 😀

  • @priyankaroberts1093

    @priyankaroberts1093

    Жыл бұрын

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

  • @kefistefi
    @kefistefi2 жыл бұрын

    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.

  • @sanghvian
    @sanghvian3 жыл бұрын

    legend

  • @abdullahawisimulaha
    @abdullahawisimulaha3 жыл бұрын

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

  • @eyotajr
    @eyotajr3 жыл бұрын

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

  • @caesarbala

    @caesarbala

    3 жыл бұрын

    Es7 react redux

  • @dali5010
    @dali50102 жыл бұрын

    Good

  • @goodToBeConfidential
    @goodToBeConfidential5 ай бұрын

    whats the configuration of your computer?

  • @rohandevaki4349
    @rohandevaki43493 жыл бұрын

    can you please create one more video , where we imlpement fetch web api in a cusom hook?

  • @joedu7320
    @joedu73209 ай бұрын

    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

    8 ай бұрын

    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.

  • @rohandevaki4349
    @rohandevaki43493 жыл бұрын

    actually i tried the same code with a signle function , in the same component, and it works fine, but i cant use useEffect inside a function,for that i just made a if check, and if we want to use a useEffect inside a function, that must be a react component, or a custom hook, that is fine, but here the important thing is with a custom hook we can use it several times, instead of writing the code again and again, thanks for the awesome video,

  • @randyfix3546
    @randyfix35462 жыл бұрын

    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?

  • @orennkimg6851
    @orennkimg68513 жыл бұрын

    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

    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

    3 жыл бұрын

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

  • @syedalimehdi-english
    @syedalimehdi-english3 жыл бұрын

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

  • @kinstar

    @kinstar

    2 жыл бұрын

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