When would you use useReducer instead of useState?
Simple meaning
When the next state depends on several fields and event types, a reducer documents the transitions in one place.
Open the full page for Why, Steps, Example and Key takeaway.
Panel-ready Frontend Master questions for freshers and experienced developers. Practice at Coding Cadre in Faridabad, or Online from Delhi NCR.
When the next state depends on several fields and event types, a reducer documents the transitions in one place.
Open the full page for Why, Steps, Example and Key takeaway.
I virtualize so only visible rows mount, using a library like tanstack virtual.
Open the full page for Why, Steps, Example and Key takeaway.
Debounce delays when the update even starts.
Open the full page for Why, Steps, Example and Key takeaway.
Reselect or createSelector returns the same reference if input slices did not change, so useSelector's equality check skips render.
Open the full page for Why, Steps, Example and Key takeaway.
Context is for rare global UI config.
Open the full page for Why, Steps, Example and Key takeaway.
SSR is always fresh and more expensive per request, good for user-specific HTML.
Open the full page for Why, Steps, Example and Key takeaway.
They run on the server, can read files or databases, and ship zero client JS for that component.
Open the full page for Why, Steps, Example and Key takeaway.
I keep secrets in server-only modules and never pass them as props to client components.
Open the full page for Why, Steps, Example and Key takeaway.
Server and client format Date differently by timezone, or I generate Math.random in render.
Open the full page for Why, Steps, Example and Key takeaway.
I wrap the await in try catch and set error state or show a toast.
Open the full page for Why, Steps, Example and Key takeaway.
The server can flush HTML in chunks as Suspense boundaries resolve instead of waiting for the whole tree.
Open the full page for Why, Steps, Example and Key takeaway.
UseLayoutEffect runs after DOM updates but before the browser paints, so I can measure and adjust without flicker.
Open the full page for Why, Steps, Example and Key takeaway.
Middleware runs on the Edge before the request hits a page, good for redirects, A/B cookies, and auth gates.
Open the full page for Why, Steps, Example and Key takeaway.
Error boundaries still require a class or a small wrapper library because there is no hook for it.
Open the full page for Why, Steps, Example and Key takeaway.
Normalization stores entities by id in a map plus an array of ids for order.
Open the full page for Why, Steps, Example and Key takeaway.
Streaming can send the shell quickly so TTFB and first paint improve even if a slow widget is still pending.
Open the full page for Why, Steps, Example and Key takeaway.
React matches by key, so state lives with the identity, not the position.
Open the full page for Why, Steps, Example and Key takeaway.
I keep a small set of variants, sizes, and an asChild or polymorphic pattern so consumers do not fork the CSS.
Open the full page for Why, Steps, Example and Key takeaway.
useMemo caches an expensive calculated value between renders.
Open the full page for Why, Steps, Example and Key takeaway.
React.memo wraps a component so it skips re-render when props are shallow-equal.
Open the full page for Why, Steps, Example and Key takeaway.