Ans: Context API in React is used in some scenarios which are as follows:
1. When we have a global state that needs to be accessed by multiple components.
2. When we have deeply nested components that need to access data from a parent component without having to pass props down through every level of the component tree
3. When we have data that needs to be updated by one component and then accessed by another component that is not a direct parent or child.
Ans: A custom hook is a reusable function in React that encapsulates common logic that can be shared between components. Custom hooks allow us to extract stateful logic from a component and reuse it across multiple components in our application. They are a way to abstract complex logic and state management away from the components, making them simpler and easier to maintain.
Ans: useRef is a React hook that allows you to create a mutable reference to an element or a value that persists across re-renders of a component. It returns a JavaScript object with a current property that can be assigned a value or an object, and this value or object can be accessed throughout the lifecycle of the component.
Ans: useMemo is a React hook that allows you to memoize the result of a function so that it only re-computes the result when the dependencies of the function have changed. It is used to optimize performance by preventing unnecessary re-computations of expensive calculations, especially in cases where the computation is triggered frequently.