Questions & Answer

How does context api works?

The React Context API is a way for a React app to effectively produce global variables that can be passed around. This is the alternative to "prop drilling" or moving props from grandparent to child to parent, and so on. Context is also touted as an easier, lighter approach to state management using Redux.

What is the purpose of react router?

React Router is a JavaScript library used to handle client and server-side routing in React applications. It allows the creation of single-page web or mobile apps that allows navigation without the page refreshing. React Router also gives us access to browser history features while maintaining the correct view of the application. React Router uses a component-based approach to routing. It provides different routing components as needed by the application.

About useRef()
  • The useRef Hook lets us create mutable variables inside functional components. There are three main key points that you should keep in mind when using the useRef Hook.
  • A ref created with useRef will be created only when the component has been mounted and preserved for the full lifecycle.
  • Refs can be used for accessing DOM nodes or React elements, and for storing mutable variables (like with instance variables in class components).
  • Updating a ref is a side effect so it should be done only inside a useEffect (or useLayoutEffect) or inside an event handler.