React Assignment – 9
Basic Questions
- Build a counter component where the button’s onClick increments, and memoize the button component using React.memo.
- Use useCallback to memoize a click handler that increments a counter. Verify child doesn’t re-render unnecessarily.
- Build a component that calculates a heavy sum of numbers. Optimize the calculation with useMemo.
- Create a list filter: type in an input and filter items using useMemo so filtering recalculates only when needed.
- Use React.lazy to lazy load an About component inside a router.
- Wrap the lazy component in Suspense with a fallback loading spinner.
- Create a reusable Button component that accepts label and onClick via props.
- Build a reusable InputField component with label, type, and placeholder as props.
- Build a controlled input form where the parent fully controls the input state.
- Build an uncontrolled form input using ref to read value instead of state.
- Create two components — Parent (updates frequently) and Child. Prevent Child from re-rendering using React.memo.
- Add a Profiler around a component tree and log its render timings in the console.
- Create a simple custom hook useCounter that provides count, increment, and decrement.
- Build an HOC that takes any component and adds a border around it.
- Build a compound component Tabs where TabList and TabPanel work together.
- Use automatic batching: update two separate states inside one handler, and ensure they batch in React 18+.
- Simulate a long computation (for loop) and memoize its result — show the efficiency with and without useMemo.
- Build a ToggleSwitch reusable component with on/off as props.
- Wrap three components in Suspense and show fallback until all have lazy-loaded.
- Memoize a derived value (fullName = first + last name) using useMemo.
Intermediate Questions
- Build a reusable Modal component using composition (header, body, footer as children).
- Create a custom hook useLocalStorage to get/set values inside local storage.
- Create a custom hook useLocalStorage to get/set local storage values.
- Build a higher-order component withLogger that logs props passed to wrapped components.
- Create a SearchableList that optimizes filtering with useMemo and avoids re-renders with useCallback.
- Use React Profiler to analyze performance of a large list rendering and log results to console.
- Build a reusable Form component that accepts render props for controlled form fields.
- Create a controlled CheckboxGroup with multiple checkboxes managed in parent.
- Create an uncontrolled FileUpload input, reading value using ref.
- Build a lazy-loaded Dashboard page with nested lazy child components.
- Implement a compound component-based Dropdown (Dropdown, DropdownToggle, DropdownMenu) pattern.
- Create an expensive calculator function inside a component and memoize its result with useMemo.
- Use useCallback to memoize event handlers for list items in a long list.
- Build a pagination component that is reusable and accepts totalPages, currentPage, onChangePage.
- Build an HOC withTheme that injects a theme prop into wrapped components.
- Create a custom hook useFormInput for managing form input state and validation.
- Optimize an image gallery using React.memo on individual ImageCard components.
- Create a reusable Table component with dynamic columns definition passed via props.
- Use Suspense to lazy load a UserProfile component and display fallback while loading.
- Implement a compound-slider component (Slider, SliderThumb, SliderTrack) where children communicate via shared context.
Advanced Questions
- Create a form builder using compound components (Form, Field, SubmitButton) where all state is managed in the parent.
- Build a fully reusable DataTable component: supports controlled sorting, uncontrolled row selection, and pagination.
- Create a custom hook useFetchWithCache that fetches data and caches it locally (similar to React Query lite).
- Develop an infinite scroll list with heavy computation per item, optimized via useMemo and React.memo.
- Create a dynamic ThemeProvider compound component (ThemeProvider, ThemeButton, ThemeText) that propagates theme through context.
- Build a performance-debugging playground: render 1000 items, analyze with Profiler, then optimize with useMemo + useCallback.
- Implement a lazy-loaded route group where multiple subpages load only when requested. Test fallback UI.
- Build an HOC withAuthCheck that restricts access to a wrapped component and redirects to Login if not authenticated.
- Demonstrate concurrent rendering + automatic batching: trigger multiple async state updates (e.g., setTimeout, fetch) and show React batches them.
- Implement concurrent updates (React 18 automatic batching) — simulate multiple async state updates and compare renders before/after batching.