React Libraries Best Practices
A condensed summary of the 25 most important best practices drawn from every page in this section.
Search across all documentation pages
A condensed summary of the 25 most important best practices drawn from every page in this section.
🤖 Read the SystemsArchitect.io Blog for over 100+ cloud architecture articles 🔥
result.toDataStreamResponse() (not result.text or NextResponse.json); otherwise you ship a full-response JSON blob and the useChat streaming UI never updates token-by-token.maxSteps default to a single step, so the model can call a tool but never see its result and the conversation stalls - raise it to the maximum reasoning depth you actually want.generateObject({ schema }) with a Zod schema enforces shape at the SDK layer; prompting for JSON and hand-parsing is brittle and wastes tokens on format instructions.InvokeCommand rejects plain objects at runtime - wrap with new TextEncoder().encode(JSON.stringify(payload)) and decode the response symmetrically, respecting the 6 MB sync / 256 KB async payload ceilings.FunctionError field on the response, not as a thrown exception, so inspect the response envelope - async (Event) invocations drop errors silently unless you configure a DLQ.DescribeVoicesCommand before switching voices.TextType: "ssml" and must be valid XML inside <speak>...</speak> with &, <, > escaped; also avoid pcm output for browsers since it is raw audio - use mp3 or ogg_vorbis.PUT directly to S3 so large uploads bypass the Next.js request body limit (1 MB default) and never touch your server bandwidth.PUT method, and the Content-Type header - and always set ContentType on the presigned command so the object isn't saved as application/octet-stream.@aws-sdk/client-s3, client-lambda, or client-polly from a "use client" file - credentials end up in the browser bundle and AWS SDK v3 balloons client JS; use Server Actions or Route Handlers.new Date("2026-04-06") parses date-only ISO strings as UTC midnight and shifts visibly in non-UTC zones, so prefer parseISO (plus date-fns-tz for zone-aware work) to avoid silent off-by-one-day bugs.MM is month, mm is minutes, and DD is invalid (use dd) - case mistakes compile fine and produce silently wrong strings.DragOverlay renders the drag preview outside the DOM flow and fixes the "item jumps" problem when the original slot collapses; combine with reduced opacity on the original for a stable visual.activationConstraint: { distance: 8 } (or a delay) to PointerSensor so a single click does not start a drag; without it, every click on a sortable item triggers accidental drags.lodash-es so the bundler tree-shakes unused utilities; import _ from "lodash" pulls in the whole ~70 KB CJS build even for a single helper.debounce(fn, 300) inline in render returns a fresh instance every render and never accumulates calls; wrap creation in useMemo/useCallback and call .cancel() in the useEffect cleanup so pending invocations don't fire after unmount.merge(target, source) mutates its first argument, so always pass a fresh {} (or cloneDeep first) as the target; also prefer native structuredClone over cloneDeep unless you need function or class-instance support.AUTH_SECRET, and weak secrets compromise every session - generate one with npx auth secret and use distinct values per environment so a leaked dev key never compromises prod.jwt/session callback pair and a module augmentation in types/next-auth.d.ts or TypeScript drifts from runtime.globalThis so hot module reload does not open a fresh connection pool on every save - without this the database quickly refuses connections and the dev server appears to hang.Number or String before passing to Client Components, and select only the relations you need (with include/select) to avoid N+1 queries.QueryClient inside useState(() => new QueryClient()) within a client provider; a module-level client in a Server Component leaks cache state across user requests and leaks data between users.staleTime controls when data is considered fresh and whether refetches happen; gcTime controls how long inactive queries stay in the cache - staleTime: Infinity still allows garbage collection, and mutations never auto-invalidate related queries without explicit invalidateQueries.Reviewed by Chris St. John·Last updated Jul 16, 2026
🤖 Read the SystemsArchitect.io Blog for over 100+ cloud architecture articles 🔥