Q: How do I set up Redux in a React application?
A: Install redux and react-redux, create a store using reducers, define actions (e.g., ADD_POST), wrap your React app with , and connect components via hooks or connect.
Q: What are Redux’s core principles?
– Single source of truth: All state lives in one store – State is read-only: Updates only via dispatched actions – Pure functions (reducers): Actions are handled by reducers that return new state predictably
Q: What is Redux and why integrate it with React for state management?
A: Redux is a predictable state container that centralizes the app state in a single store. It helps manage complex state logic in React by offering clarity and consistency in data flow.
Q: How do I handle shared assets like CSS or global events in micro-frontends?
A: Avoid global side effects by using scoped namespaces. Choose browser-native event APIs over global pub/sub systems, and ensure isolation by assigning unique namespaces for CSS and storage.
What are the key architectural advantages of React micro-frontends?
A: key architectural advantages of React micro-frontends are: – Faster development and deployment – Enhanced code reusability – Team-level isolation and vertical ownership – Simplified testing and progressive enhancement – Tech-agnostic setup (mix frameworks like React, Vue, Angular)
Q: How can multiple React apps share components using module federation?
A: With module federation (Webpack), you can “expose” components (like Navbar/Footer) from a host (primary) app and “import” them into a consumer (secondary) app using a remoteEntry.js manifest. This enables dynamic sharing without duplication.
Q: What is a micro-frontend and why use it with React?
A: A micro-frontend breaks a large web app into independently deployable modules, often built by different teams. It boosts scalability, improves code ownership, and allows teams to ship updates faster.
Q: How to test FastAPI pagination endpoints using Swagger UI and Pytest?
A: Use FastAPI’s built-in Swagger UI (/docs) to test pagination manually. For automated testing, use pytest with TestClient to simulate requests and validate response structure.
Q: How to return total count of records in a FastAPI paginated API response?
A: Run two queries: one for paginated items and one for the total record count using COUNT(*). Example JSON response: { “total”: 250, “page”: 2, “limit”: 10, “items”: […] } This lets clients know how many total pages are available.
Q: What is the difference between offset-based and cursor-based pagination in FastAPI?
A: Offset-based pagination uses LIMIT and OFFSET, making it simple to implement but slower for large datasets. Cursor-based pagination uses a unique key (like an ID or timestamp) to fetch the next set of results, offering better performance and stability with frequently changing data.