Hooks in React
In this lesson, we'll start getting acquainted with hooks. We've already encountered them when we studied states - there we learned how to work with the useState state hook.
In general, hooks are regular JavaScript functions whose names begin with the word 'use'.
Hooks allow us to use states and other React features without using classes. They make it easier to reuse code for different tasks, as well as test it, and help break down complex components into simpler functions according to their purpose. Some hooks can even replace the functionality of Redux. In addition, hooks help improve the performance of the application.
If you want to use hooks, there are two basic rules to follow. First, use them only at the top level - don't call them inside loops, conditionals, or nested functions. Second, hooks should only be called from React functions (either React components or custom hooks), not regular JavaScript functions.
Another mistake that programmers make is the uncontrolled use of hooks in the code. Before using a hook, make sure that it is really necessary.
In the next lesson we will look at the types of hooks.