React JS Interview QA
React JS Interview QA
A: Lazy loading in React is a design pattern that delays loading components until they're actually
needed, improving performance by reducing initial load time. Its commonly used in large
**Example:**
```jsx
function App() {
return (
<div>
<h1>Welcome</h1>
<Suspense fallback={<div>Loading...</div>}>
<LazyComponent />
</Suspense>
</div>
);
```
Here, `LazyComponent` is only loaded when rendered, and until then, a fallback UI is shown.
- Incremental rendering
Fiber allows React to split work into units and spread them out over multiple frames, improving
responsiveness.
A: React's diffing algorithm helps efficiently update the DOM by comparing the previous and next
Key optimizations:
- Developers can use `key` prop in lists to hint React about element identity.
A: - **Redux**: Best for large-scale applications needing centralized global state, middleware (like
- **useReducer**: Great for medium-complex components needing complex state logic; works well
with Context.
- **Context API**: Good for passing down props like themes or user info. Not optimal for
A: HOCs are functions that take a component and return a new component with additional props or
behavior.
**Example:**
```jsx
console.log('Props:', props);
};
};
```
A: - **CSR (Client-Side Rendering)**: React app is rendered in browser after loading JavaScript.
- **SSR (Server-Side Rendering)**: HTML is rendered on the server, improving performance and