01 / 03

List all the hooks available in react js and provide brief definition for each

It is a lightweight in-memory representation of the actual DOM to track changes in the UI and efficiently update the real DOM when necessary.

  1. 1

    useState: to add and manage state to functional components

  2. 2

    useReducer: to add and manage complex state

  3. 3

    useEffect: to execute side effects during rendering and hooking into lifecycle hooks

  4. 4

    useMemo: to memoise the output of a function

  5. 5

    useCallback: to memoise a function declaration when a function is passed to children components that are memoised.

  6. 6

    useContext: to access context object

  7. 7

    useLayoutEffect: synchronously useEffect

  8. 8

    useRef: to access and manipulate DOM and store values that do not cause rerender on updates.

  9. 9

    use

  10. 10

    useDebugValue

  11. 11

    useId

  12. 12

    useDeferredValue

  13. 13

    useTransition

  14. 14

    useSyncExternalStore

  15. 15

    useInsertionEffect

  16. 16

    useImperativeHandle

Difficulty: 6/10
Topics: React Hooks, State Management, Performance

Scenario Questions

0-2 years experience
  1. 1

    How would you add a piece of local state to a functional component that toggles a modal open and closed? Which hook would you use and why?

  2. 2

    If you need to run some code once after a component mounts to fetch initial data, which hook would you choose and what would the dependency array look like?

  3. 3

    What happens if you call a hook conditionally inside an if statement? Explain the rule that prevents that.

2-5 years experience
  1. 1

    You have a component that fetches user data in useEffect, but it keeps refetching on every render. Walk me through how you'd debug the dependency array.

  2. 2

    When would you prefer useReducer over useState for managing form state in a medium‑sized feature? Discuss trade‑offs.

  3. 3

    Explain how you would create a custom hook to share a WebSocket connection across multiple components, and how you'd handle cleanup.

5-8 years experience
  1. 1

    A list component suffers from unnecessary re‑renders because a callback prop changes on each render. How would you use hooks to mitigate this and what are the performance implications?

  2. 2

    You need to expose an imperative method (e.g., focus) from a child functional component to its parent. Which hook would you use and how would you implement it?

  3. 3

    Describe how you would refactor a large class‑based component that uses lifecycle methods into a functional component using hooks, ensuring behavior stays identical.

8+ years experience
  1. 1

    Your organization is migrating a legacy codebase of 200+ class components to hooks. What strategy would you propose to do this incrementally while minimizing risk?

  2. 2

    How would you design a shared state solution across many unrelated parts of the app using hooks, and what are the considerations for scalability and testing?

  3. 3

    When introducing a new custom hook library across multiple teams, what guidelines and patterns would you establish to keep the API stable and avoid hook misuse?

Follow-up Questions

  • Can you give an example where useMemo might actually degrade performance?
  • What are the consequences of omitting the dependency array in useEffect?
  • How would you test a custom hook that uses useRef internally?