React Assignment – 3
Basic Questions
- Create a simple error boundary class component using componentDidCatch.
- Wrap a child component with an error boundary and test by forcing an error.
- Display a fallback UI message in the error boundary when a child component crashes.
- Create a reusable error boundary component named ErrorBoundary.
- Use ErrorBoundary around multiple independent components.
- Cause a runtime error in a component (e.g., undefined.map) and let error boundary catch it.
- Demonstrate logging an error (using console.log) inside componentDidCatch.
- Practice catching errors only in specific parts of the UI.
- Show that error boundaries do not catch event handler errors. Fix by adding try/catch in events.
- Show that error boundaries do not catch async errors in promises. Handle with .catch().
- Fetch data from a dummy API and display error if the API fails.
- Display a “Loading…” state, and show an error message if fetch is rejected.
- Wrap fetch logic in try/catch with async/await and show error UI.
- Use error state with useState to render error message when API call fails.
- Import a component using a relative path (../components/Button).
- Import the same component using an absolute path (src/components/Button).
- Compare both imports in the same project and confirm output is same.
- Change a deeply nested import (../../../Header) into an absolute path import.
- Create two different components and import one with a relative path, the other with absolute path.
- Demonstrate how absolute imports simplify file structure navigation.
Intermediate Questions
- Build a reusable ErrorBoundary component that accepts a custom fallback UI as props.
- Wrap only a specific section of a page (not the whole app) with an error boundary.
- Simulate an error in one child and show that unaffected children still render.
- Create multiple nested error boundaries and log where they catch errors.
- Store caught error details in component state using componentDidCatch.
- Display different fallback UIs depending on error types.
- Add error tracking integration by logging errors to a fake monitoring service from componentDidCatch.
- Demonstrate catching and handling rejected promises inside React components.
- Write a function that wraps API calls with a try/catch and custom error messages.
- Handle form submission errors gracefully (invalid input + API error).
- Convert an entire project’s imports from relative to absolute paths using jsconfig.json/tsconfig.json.
- Compare readability of imports in a file before and after converting to absolute paths.
- Break a component into sub-components and test imports using both relative and absolute style.
- Show issues when moving files around in relative imports vs stability with absolute imports.
- Document advantages/disadvantages of each approach in comments inside code.
- Create a reusable useApi hook that returns {data, error, loading}.
- Handle API error by retrying fetch when the user clicks “Retry”.
- Display a dedicated error page component on API failure.
- Handle Nested API call error (fetch posts, then comments → fail second fetch).
- Combine error boundary + API error handling to capture both UI + backend errors
Advanced Questions
- Create a global app-level error boundary that catches crashes and routes to an error page.
- Implement a logging service (fake API) where every caught error in componentDidCatch is sent to backend.
- Build a complex example: one component fails, another continues, error boundary shows partial fallback UI.
- Combine ErrorBoundary with React Router to redirect to an error page when an error is caught.
- Implement a retry mechanism in API fetching logic that retries failed requests 3 times before failing.
- Handle both sync + async errors gracefully: runtime, API fetch, and promise rejection in one project.
- Migrate an entire React project from relative imports to absolute imports and measure line changes.
- Create a project structure (/components, /pages, /hooks) and test maintainability with absolute imports.
- Build two versions of a medium app with relative vs absolute imports, list pros/cons in README.
- Create a large project demo (10+ components) where some imports break when refactoring. Show how absolute imports prevent errors.