I have to say, learning React has been a blast. I really enjoy the library and have come to appreciate its nuances and become intimately familiar with some of its peculiarities. My learning has been supplemented by a vast number of tutorials. Anytime I have a curiosity, I’m almost always able to find an article or a video about it.
##What Is A Hook?
I remember hearing about their introduction as I listened to the Syntax.fm podcast with Wes Bos and Scott Tolinksi. I didn’t really get them, not at first at least. As the subject kept popping up more and more in my feeds–I decided to take a dive.
I was hit by clean and easy to understand logic. Using plain old functional components was a dream to me. These hooks just made sense. There was less abstraction, less having to work around the mechanics of classes. (Mind you, I love classes for what they do, but in my inexperienced opinion, I feel like they are circumstantial.) Right off the bat I was sold and, most of all, excited.
I had a lot to learn still before I could tap them as a resource.
##Fine, I’ll Convert Everything
I challenged myself, “I will follow the tutorials, I will learn what they are teaching me. And afterward, I will convert everything over to hooks.” At first it was a mess. I struggled and wracked my brain against them and what I knew already.
As repetition did its wonders a couple of days passed and I was crushing it with useState, useEffect, and useContext. I felt like a pro. My components were looking crisp and organized. I was feeling good.
I realized I was doing a lot of copy pasting and the same things over and over. Having learned about DRY, I started to ease my way towards custom hooks. They were supposed to be little nuggets of reusable logic, right? The idea of making my own custom anything seemed intimidating at first, like something a true React wizard could only do.
But, I sat down and I wrote my first one. It didn’t work. So, I fiddled with it.
It was then the beauty of hooks finally set in as I got it doing what I wanted. The doors opened in my mind and I was flooded with revelation.
I was able to get just why custom hooks are so powerful, so portable, and so important.
Now, I have begun to wield them with confidence.
##Lesson I Learned
I need to be fearless when engaging with my learning content. Take what I’m learning, absorb the concepts, and challenge myself with said concepts. In the future, I think I’ll take this to the next level. Soon as I learn something new, I want to test its limits by building something different than the example in the tutorial.
I feel like programming is less about memorization, and more about building a “muscle memory” for handling logic. You have to put in the paces, you have to practice just like you would tying your shoes as a kid, riding a bike, throwing a football, or typing on a keyboard. The more you struggle and push yourself early on, the less you will have to later.