Introducing React Hooks in 5 Minutes
Introducing React Hooks in 5 Minutes

Hello and welcome back to the channel. In this video I will tell you why do you need to learn React hooks if you are a React developer or you are learning React.
Let's jump right into it.

So what are React Hooks? It's a new concept of writing React application which was introduced starting with React 16. The main idea is to be able to work with state without writing a class.

As you remember in React to normally are writing either classes or stateless components. And stateless components are normally preferable just because they are plain functions without this, inner state and you simply write less code. But you can't write a state inside stateless function. This is actually why they are stateless. But now with the help of hooks are can do that.

Let's check on the example. So here is our standard class with inner state. Now on the right you can see how the same code looks with hooks. So we have a function where inside we have this magic construction useState which returns us a value and a setter. I don't want to go too deep in hooks in this video but this is just that you see that it's a new way of writing code.

The question is if it's more efficient or better than writing classes. From my point of view it's not good a bad but it's just other way with other problems. But from my experience and the other people learning curve I can say that hooks look easy but actually they are difficult. And it's much more difficult to write good code with hooks or start using hooks than it was with classes.

So what are the benefits? First of all you get away from classes completely so you always write just functions. You don't have this, binding this to be correct, extends and all this nasty things from classes and oriented programming that you had.

Also as you saw in the example with useState now React just gives us a possibility to write just plain functions with state inside which is good.

But with classes we had all this nice life cycles methods where we can fetch for example data when our component is mounted or changed and update whatever you want. We don't have life cycles in React hooks at all so it's more about changing you developing of application and your mentality of thinking how you describe you component and changes.

Also hooks is a lot about rerendering and understanding how many times your component rerenders and it can be quite tricky to debug why it is happening more often than it should. We will talk about it deeper in the next videos.

Now the question is if you need to learn them or not? Classes in React are not deprecated yet and React team is saying that they are not planning to remove classes support (but you never know). The main point with React Hooks is that a lot of libraries are written with hooks now, people are writing new applications in Hooks or rewrite older applications in hooks. So it's not even about liking or disliking hooks. It's a future of React which you must learn if you want to work as a React developer.

But it's worth mentioning that it's much easier to start using React with classes and plain stateless components. So if you just want to start learning React I can't recommend you to jump directly in hooks.

I hope that this video brought you understanding what are hooks and that you actually don't have other choice but to learn them.

Also if you want to improve your programming skill I have lots of full courses regarding different web technologies.