Contents of React Interview Questions

Comprehensive collection of React interview questions and answers covering hooks, components, state management, and best practices.

What is Context API in React and why is it used?

The Context API is a feature in React that allows you to share values (like state, themes, or user information) between components without having to manually pass props at every level. It helps manage "global" data in a clean and efficient way.

Why is it used?

  • To avoid prop drilling (passing props through many layers).
  • To manage application-wide settings (like theme, authentication, language preferences).
  • To improve code readability and ease of maintenance.

Example use cases: authentication status, theme switching (light/dark mode), user language settings.