About React Hooks

About React Hooks

1. Explain React class component and Hooks?

Answer: Hooks gives us the adaptability to carry out lifecycle techniques. Not at all like the class-based part approach, the Hooks lifecycle techniques in a utilitarian Hooks part gives the developer to choose how firmly or approximately coupled the lifecycle strategies. In the class-based methods, any arrangement that was done in componentDidMount would need to make esteems accessible to componentWillUnmount to tidy up (for example the span ID when calling setInterval). Utilizing Hooks, there is no compelling reason to do this since the mounting and unmounting rationale is encased inside a similar capacity scope. Furthermore, assuming that there was a need to have a partition between the mounting Hook and the unmounting Hook, the developer can select to utilize two separate Hooks and handle the cases freely. Utilizing React Hooks, it is feasible to have the smartest possible solution in a straightforward and reusable manner.

2. Explain React Custom Hooks.

Answer: Hooks have a great deal helpful for us as developers, and they will change the manner in which we compose parts to improve things. They as of now assist us with composing more clear and more succinct code — it resembles we went on a code diet and we lost a great deal of weight and, we look better and feel much improved. It draws out our facial structure and causes us to feel lighter. It’s the one change that works for us. Simply see how React Hooks have helped others!
Custom hook is used when same function / piece of code is needed to use in different places.
While creating a custom hook file name should be started with use keyword for example useAuth.js. It’s not mandatory but it’s conventional way. After that we have to export that file and the function should return some values that we can use afterwards.