React Hooks
#Lets us use state and other React features without writing a class
Most developers prefer using functional components over class-based components for the simple reason that functional components require less coding. However React Hooks lets us implement state changes and lifecycle methods within a functional component. React Hooks also improves readability and organization of the components.
In the previous post, we learnt about defaultProps Explained In Detail With Example. You can check the previous topic here.
useState():
- “useState” is one of the React Hooks used to update state of the component.
General syntax of useState():
const [state, setstate] = useState(initial state)
state -> state variable name
setstate ->set(state variable name)
initial state -> initial value of the state variable before update
Get Vinitha Subhash’s stories in your inbox
Join Medium for free to get updates from this writer.
Comparing setState (used in class components) and useState (used in functional components):
List of most used React Hooks:
- useState — To update the state value.
- useEffect — Used to perform side effects in function components.
- useContext — To impliment contextAPI functionality.
- useReducer — useReducer is an alternative version of useState for more complex state changes.
- useCallback — Returns its function when the dependencies change.
- useMemo — Calls its function and returns the result.
- useRef — Returns a mutable ref object.









