what is Hook ?
- In React, a Hook is a special function that lets you “hook into” React features like state and lifecycle methods inside functional components.
- Before hooks were introduced, features like state and lifecycle could only be used in class components. With hooks, you can now use these powerful features directly in functional components — making them more powerful and easier to use.
Commonly Used Hooks
Here are the most commonly used built-in hooks:
- useState() – Adds state to a functional component.
- useEffect() – Runs side effects (e.g., API calls, DOM updates, timers).
- useContext() – Accesses context values without using props.
- useRef() – Accesses or stores a DOM element or mutable value.
- useMemo() / useCallback() – Optimize performance by memoizing values or functions.
Top comments (0)