1.What are React hooks?
Ans: React Hooks are functions that allow functional components in React to have state, lifecycle methods, and other functionality that was previously only available to class components.
- Explain the useEffect hook ?
Ans: useEffect is a hook to perform side effects in functional components. It runs on every render and can be used to fetch data, subscribe, manually modify the DOM etc.
- What is the useState hook ?
Ans: The useState hook in React is used to add state variables to functional components so that they can track state changes and trigger re-renders.
- What is the purpose of useReducer hook ?
Ans: useReducer is a hook in React used for state management. It is suitable for managing complex state logic with multiple sub-values or when the next status depends on the previous status.
- What is the purpose of useCallback hook in React ?
Ans: useCallback is used to store callback functions and prevent unnecessary re-rendering of child components that depend on these callbacks.
- Explain the concept of Hook rules in React ?
Ans: The rules for using Hooks in React include that they are called at the top level, they are called only from function components or custom Hooks, and they follow a naming convention. For example- starting with “use”.
- What is the purpose of useMemo hook in React ?
Ans: useMemo hook is used to store the results of calculations. It helps in performance optimization by preventing unnecessary recalculations.
- What is the importance of useRef hook in React ?
Ans: useRef is used to create mutable object properties that persist across multiple renders without re-rendering when a change occurs. It is often used to access and change properties of DOM elements.
- What is PureComponent in React ?
Ans: PureComponent is a base class for class components that implements the shouldComponentUpdate method to do superficial property and state comparisons. This helps prevent unnecessary rendering for performance optimization.
- What are React Fragments ?
Ans: React Fragments allow you to group multiple elements together without adding unnecessary nodes to the DOM. This is useful when you don’t want to introduce an additional parent div.
- What is the importance of keys in React lists ?
Ans: Keys are used to help React detect which items in the list have changed, added, or removed. They help optimize the rendering process.
- What is React’s Context API ?
Ans: The Context API provides a way to pass data through a component tree without having to manually pass props at each level.
- How does React Prop handle drilling ?
Ans: Prop drilling occurs when you route a prop to multiple component levels. The solution is to use Context API or Redux for global state management.
- What is the importance of keys in React lists ?
Ans: Keys are used to help React detect which items in the list have been changed, added, or removed. They help in optimizing the rendering process.
- Explain the concept of lazy loading in React ?
Ans: Lazy loading is a technique where a component or resource is loaded only when it is actually required. React provides the React.lazy feature to lazily load components.
Top comments (0)