React Hooks
Hooks are added in React version 16.8. They are built in functions and they are used to use state and other react features in React functional components. They can only be used in functional components but not React class components. They usually help you to write stateful components and use React lifecycle features without writing a class component.
Most Common React Hooks
-
useState: Manages states in React functional components.
-
useEffect: Handle side affects in function components like data fetching, manipulating DOM elements etc.
-
useContext: Provides a way to share data through components tree (parent to child or vice versa).
-
useReducer: Similar to useState hook but used to perform more complex state logic.
-
useRef: Commonly used to access DOM elements directly or to store mutable variables that don't cause a re-renders when updated.
-
useCallback: It is used to memorize a function and ensuring that the function is not re-created on every render unless it's dependency changes.
-
useMemo: Provides similar features like useCallback but it returns memorized value than function and reduce performance issues by stopping unnecessary re-rendering.