If you want to use Hooks in
React in your application. Make sure you update your react version to
>=16.8 since it was introduced in
Before React Hooks was a feature in React the only way to use state in your component was to write your component as ES6 Class. Now, with React hooks you can use state and other React features without writing a class.
You can try Hooks in a few components without rewriting any existing code. But you don't have to learn or usee Hooks right now if you don't want to. It is 100% backwards-compatible.
Hooks only is an alternative way to use React concepts you already know: props, state, context, refs, and lifecycle but without classes. Hooks allow you to reuse stateful logic without changing your component hierarchy
Function components don't need a constructor. You can initialize the state in the
useStatecall. If a computing the initial state is expensive, you can pass a function to
Instead of using
useEffectcan express all combinations of all the standard lifecycles like
There are no hooks yet for handling exceptions in your component.
Hope this article helps you understanding a motivation behind why Hooks were introduced but many details will be probably unclear. Click this link to deep dive into Hooks
This blog was originally published on my personal blog Viral Patel.