Day-4 React with Me
On day 4 I dived deep into hooks and discovered 3 new hooks which will help me making my next mini project called a password generator.
useEffect, useRef
, and useCallback
are three such hooks that play crucial roles in managing state and interactions within React components.
The useEffect
hook is used to perform side effects in functional components. Side effects can include data fetching, subscriptions, or manually changing the DOM. It is similar to componentDidMount, componentDidUpdate, and componentWillUnmount in class components.
The useRef
hook creates a mutable reference object whose .current
property can hold a value. This value persists across renders and does not trigger a re-render when it's updated.
The useCallback
hook returns a memoized callback function. It is useful when passing callbacks to optimized child components that rely on reference equality to prevent unnecessary renders.
For Reference -
https://react.dev/reference/react/useEffect
Subscribe to my newsletter
Read articles from Piyush directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by