React Assignment – 6
Basic Questions
- Replace a useEffect with useLayoutEffect and log when each runs to see timing difference.
- Use useLayoutEffect to measure DOM element width immediately after render.
- Create a component where text flashes briefly without useLayoutEffect, then fix with it.
- Compare console logs between useEffect and useLayoutEffect.
- Create a custom input component using forwardRef.
- Expose an input’s .focus() method using useImperativeHandle.
- Add a custom method clear() inside an input component via useImperativeHandle.
- Demonstrate that without useImperativeHandle, parent cannot call a child method.
- Create unique ids for multiple input fields using useId.
- Use useId to associate <label> with <input> for accessibility.
- Generate IDs in multiple components and show they remain unique across render cycles.
- Use useTransition to show “Loading…” while filtering a large list.
- Make a button that triggers expensive state update inside a transition for smoother UI.
- Compare rendering with and without useTransition.
- Use useDeferredValue to defer rendering a large filtered list.
- Display a search box where input updates immediately but results render deferred.
- Create a basic external store (counter object) and connect it with useSyncExternalStore.
- Log updates whenever the store value changes.
- Use useInsertionEffect to inject a console log before DOM mutations.
- Compare useInsertionEffect execution order with useLayoutEffect.
Intermediate Questions
- Create a component that smoothly scrolls to bottom when new messages are added using useLayoutEffect.
- Measure an image’s height with useLayoutEffect before displaying it.
- Demonstrate race condition issue with useEffect and solve using useLayoutEffect.
- Build a reusable Modal component exposing open() and close() methods.
- Create a Form component where parent resets all input fields by calling child method via useImperativeHandle.
- Expose multiple child component functions (focus + validate) using useImperativeHandle.
- Compare difference: controlling input via props vs controlling via parent ref using useImperativeHandle.
- Create custom component PasswordInput exposing method to toggle visibility.
- Generate unique keys for multiple dynamic form fields using useId.
- Compare hardcoded IDs vs generated IDs in repeated lists.
- Implement a large item search list and optimize rendering using useTransition.
- Add spinner UI when isPending is true with useTransition.
- Build a filterable gallery with fallback UI during transition.
- Demonstrate smoother typing experience for a large filtered list with useTransition.
- Implement deferred rendering in a live search box with thousands of items.
- Render a Markdown preview where text input updates instantly but preview rendering uses useDeferredValue.
- Implement a basic theme store and sync theme changes with components using useSyncExternalStore.
- Build a custom hook wrapping useSyncExternalStore for subscribing to window.innerWidth.
- Use useInsertionEffect with a CSS-in-JS library simulation to inject styles early.
- Demonstrate difference in flickering when injecting styles via useEffect vs useInsertionEffect.
Advanced Questions
- Build a chat app UI where latest message auto-scrolls using useLayoutEffect.
- Create a tooltip system that dynamically repositions based on text width using useLayoutEffect.
- Create a video player component exposing play/pause methods to the parent via forwardRef + useImperativeHandle.
- Create a carousel/slideshow exposing next(), prev(), and goToSlide() methods controllable by parent.
- Build a live product search where typing input updates instantly but the large product list renders deferred.
- Use useTransition to implement smooth UI updates in a multi-tab dashboard where heavy data loads don’t freeze UI.
- Combine useDeferredValue + useTransition for typing + filtering in a massive dataset UI.
- Implement a real-time external clock store synced to all components via useSyncExternalStore.
- Build a global dark/light theme management system using useSyncExternalStore for subscription + useInsertionEffect for injecting CSS variables.
- Optimize a CSS-in-JS styled app so styles are injected without flicker using useInsertionEffect.