React Hooks
React was created by Jordan Walke, a software engineer at Facebook, who released an early prototype of React called "FaxJS". He was influenced by XHP, an HTML component library for PHP. It was first deployed on Facebook's News Feed in 2011 and later on Instagram in 2012.It was open-sourced at JSConf US in May 2013.
However, only after 8 years, On February 16, 2019, React 16.8 was released to the public,the release introduced React Hooks.
Hooks are functions that let developers "hook into" React state and lifecycle features from function components. They make codes readable and easily understandable. Average developer spend one tenth of time writing code and the rest reading and digging through his or someone else's composure. React hooks make this process way easier, hooks don’t work inside classes ,instead they let you use React without classes.
React provides a few built-in Hooks like useState
, useContext
, useReducer
and useEffect
to name a few. They are all stated in the Hooks API Reference, useState
and useEffect
, which are the most used, are for controlling states and side effects respectively in React Components and useEffect
There are rules of hooks which must be followed before they can be used. Hooks should only be called at the top level (not inside loops or if statements)and they should only be called from React function components, not normal functions or class components
Essentially the biggest benefit of the React hooks is that when you use classes you end up with complex components with stateful logic. It is hard to deal with those components because they relies on the React Lifecycle methods. Instead hooks allow you to break those components into smaller functions and incapsulate them into smaller units, which you can use depending on the functionality.
The two most used React Hooks are useState
and useEffect
, the first basically is a substitute to class component
and the second is a substitute for componentDidMount()
and componentDidUpdate
, however there a bunch of other useful React Hooks and ,what's even more fascinating, you can write and invent your own hooks which you can store and use in accordance to your functionality.
In conclusion we can definitely say that React Hooks is a relatively new feature, however very powerful and with a immense potential that is still growing and expanding.
Top comments (0)