tezvyn:

React & Next.js

React, Next.js, Remix, RSC, React ecosystem

302 bites

More in React & Next.js — page 14

Zod: Validate Data, Infer Types
React & Next.js2 min read

Zod: Validate Data, Infer Types

Zod acts as a bouncer for your data, validating it against a schema you define and inferring TypeScript types automatically. It's essential for validating API inputs or form submissions. The main footgun is forgetting to enable "strict": true in your tsconfig.

Formik: Taming React Form State
React & Next.js2 min read

Formik: Taming React Form State

Formik is a state machine for your React forms, managing values, errors, and visited fields without providing UI. Use it to avoid boilerplate for validation and submission. The footgun is fighting its design by trying to integrate it with global state stores.

React Hook Form: Faster Forms with Less Code
React & Next.js2 min read

React Hook Form: Faster Forms with Less Code

React Hook Form builds performant forms by using uncontrolled inputs, avoiding re-renders on every keystroke. It's ideal for complex forms where managing state with `useState` becomes slow. The main footgun: overuse of `watch()` can negate performance gains.

FormData: Package Form Data for HTTP Requests
React & Next.js2 min read

FormData: Package Form Data for HTTP Requests

The FormData API is a digital shipping container for your form's data, packaging input into a format HTTP requests understand. Use it to send forms, including files, with `fetch()` without manually setting headers.

React & Next.js88 sec read

useRouter: Programmatic Navigation in Next.js

The useRouter hook gives you a router object to programmatically control navigation. Use it for event-driven redirects, like sending a user to their dashboard after a successful login.

React & Next.js2 min read

Next.js Dynamic Routes: Pages on Demand

Think of dynamic routes as a page template. You create one file like `[slug].js` to generate unlimited unique pages for things like blog posts or products. The footgun is forgetting to handle non-existent slugs, which can crash your app.

Nested Routes: Composing UI with <Outlet>
React & Next.js2 min read

Nested Routes: Composing UI with <Outlet>

Nested routes build layouts with shared UI, like a sidebar. The <Outlet> component is a placeholder for changing content, perfect for dashboards. The footgun is forgetting the <Outlet> in the parent route; child routes will match the URL but won't render.

React & Next.js2 min read

SSR for Styles: Avoiding the 'Flash'

Server-side rendering for styles sends a fully styled page on the first load, preventing the dreaded "flash of unstyled content" (FOUC). This is crucial for CSS-in-JS libraries. The footgun is assuming it works automatically without proper setup.

React & Next.js2 min read

React Theming: Context API and CSS-in-JS

Use React's Context API to inject a theme object (colors, spacing) into your component tree for your CSS-in-JS styles. It's ideal for light/dark modes or brand skins. The footgun: this pattern fails in React Server Components, which lack context.

React & Next.js2 min read

Emotion: Component-Scoped Styles in JavaScript

Emotion lets you write CSS directly in your JavaScript, keeping styles and logic colocated. It's ideal for dynamic, component-scoped styles in React that avoid global conflicts.

React & Next.js2 min read

Integrating Sass/SCSS in Next.js

Next.js has built-in Sass support, letting you use variables, mixins, and nesting. Import .scss files for component-scoped styles or global stylesheets. The main footgun: you must install the `sass` package yourself; it's not included by default.

React & Next.js2 min read

Global vs. Component CSS in React/Next.js

Treat CSS like any other module. Import global styles (like resets or Tailwind) once in your app's entry point. For component-specific styles, import a CSS Module file directly into your component to keep styles scoped and prevent conflicts.

Typing React Component Props with TypeScript
React & Next.js2 min read

Typing React Component Props with TypeScript

Use TypeScript to define a 'contract' for your component's props with an `interface` or `type`. This catches bugs by ensuring data passed to a component has the correct shape. The footgun: files with JSX must use the `.tsx` extension.

useDebugValue: Label Your Custom Hooks in DevTools
React & Next.js2 min read

useDebugValue: Label Your Custom Hooks in DevTools

useDebugValue attaches a readable label to your custom hooks in React DevTools. Instead of just seeing raw state, you can display a meaningful string like "Online". The footgun is overusing it; reserve it for complex, shared library hooks.

useSyncExternalStore: Safely Read from External State
React & Next.js2 min read

useSyncExternalStore: Safely Read from External State

useSyncExternalStore lets your React components safely subscribe to data outside of React's state. Use it to connect to state libraries like Zustand or browser APIs. The main footgun: your `getSnapshot` function must return an immutable, cached value.

useDeferredValue: Keep UI Responsive During Renders
React & Next.js2 min read

useDeferredValue: Keep UI Responsive During Renders

useDeferredValue keeps your UI responsive by showing a stale value while a new, expensive-to-render value is prepared in the background. Use it for search inputs filtering large lists.

useTransition: Keep Your UI Responsive During State Changes
React & Next.js2 min read

useTransition: Keep Your UI Responsive During State Changes

useTransition lets you update state without blocking the UI, keeping your app responsive. Use it for slow renders like filtering large lists, while the `isPending` flag shows a loading state.

React & Next.js2 min read

next/dynamic: Defer Loading Heavy Components

next/dynamic splits a component into its own file, loading it only when needed to shrink your initial bundle. Use it for heavy components below the fold or browser-only libraries. The footgun: forgetting a loading state causes layout shifts.

React & Next.js2 min read

Next.js Layouts: Shared UI That Survives Navigation

Think of a Next.js Layout as a picture frame that stays put while you swap the pictures (Pages) inside. It defines shared UI like headers that persist across routes, preserving state.

React & Next.js2 min read

Compound Components: Build Flexible APIs via Shared State

Think of HTML's `<select>` and `<option>`. The Compound Component pattern lets a parent manage state while children act as declarative configuration. It's used for flexible UI like tabs or accordions.