#react

44 snippets tagged with #react

typescriptintermediate

Error Boundary with Fallback UI

Class-based error boundary component that catches render errors and displays a customizable fallback UI.

Best for: Graceful error recovery

#error-boundary#error-handling
typescriptbeginner

usePrevious Hook

Track the previous value of any state or prop using a ref-based hook for comparison logic.

Best for: Detecting value changes

#hooks#state
typescriptintermediate

React Custom Hook for Data Fetching

A reusable useFetch hook with loading states, error handling, caching, and abort support.

Best for: Reusable data fetching across components

#react#hooks
typescriptadvanced

React Compound Component Pattern

Build flexible compound components using React context for shared state between related parts.

Best for: Building flexible component libraries

#react#patterns
typescriptintermediate

React Form Validation Hook

A type-safe form validation hook with field-level errors, dirty tracking, and submit handling.

Best for: Type-safe form handling without libraries

#react#forms
typescriptadvanced

React Virtual List Component

Render large lists efficiently with windowing to only mount visible items in the viewport.

Best for: Rendering thousands of list items efficiently

#react#virtualization
typescriptintermediate

React Portal Modal Component

Build an accessible modal dialog using React portals with focus trapping and keyboard handling.

Best for: Accessible modal dialogs with focus management

#react#portal
typescriptintermediate

React Intersection Observer Hook

Custom useIntersectionObserver hook for lazy loading, infinite scroll, and scroll animations.

Best for: Lazy loading components when they enter viewport

#react#hooks
typescriptintermediate

React useReducer for Complex State

Manage complex component state with useReducer pattern including typed actions and middleware.

Best for: Shopping cart state management

#react#useReducer
typescriptadvanced

React Optimistic Update Pattern

Implement optimistic UI updates that show changes immediately and rollback on server failure.

Best for: Instant UI feedback for server operations

#react#optimistic-ui
typescriptbeginner

React Responsive Breakpoint Hook

A useMediaQuery hook for responsive rendering with SSR-safe breakpoint detection.

Best for: Conditional rendering based on screen size

#react#responsive
typescriptintermediate

React Error Boundary Component

Build a reusable error boundary with retry, fallback UI, and error reporting integration.

Best for: Preventing full-page crashes from component errors

#react#error-boundary
typescriptintermediate

useThrottle Hook for Rate Limiting

Throttle rapidly-firing values like scroll or resize events with a configurable delay hook.

Best for: Scroll position tracking

#react#hooks
typescriptintermediate

useAsync Hook for Promise Management

Manage async operations with loading, error, and data states using a reusable hook pattern.

Best for: Data fetching with status tracking

#react#hooks
typescriptbeginner

useKeyboardShortcut Hook

Register global keyboard shortcuts with modifier keys, preventing defaults, and cleanup on unmount.

Best for: Command palette shortcuts

#react#hooks
typescriptadvanced

Context Selector Pattern

Avoid unnecessary re-renders with a context selector pattern that subscribes to specific state slices.

Best for: High-performance global state

#react#context
typescriptintermediate

Toast Notification System

Build a toast notification system with auto-dismiss, stacking, animations, and severity levels.

Best for: User feedback notifications

#react#toast
typescriptintermediate

useMutation Hook for Side Effects

Handle mutations (POST/PUT/DELETE) with loading, error, reset, and optimistic update support.

Best for: Form submission handling

#react#hooks
typescriptintermediate

Accessible Tabs Component

Build an accessible tabs component with keyboard navigation, ARIA attributes, and focus management.

Best for: Tab navigation interfaces

#react#accessibility
typescriptadvanced

useInfiniteQuery Hook

Implement infinite scrolling with cursor-based pagination, loading states, and intersection observer.

Best for: Infinite scroll feeds

#react#hooks
typescriptbeginner

useEventListener Hook

Safely add and clean up DOM event listeners with a type-safe hook supporting window, document, and elements.

Best for: Window resize handling

#react#hooks
typescriptadvanced

Suspense Data Fetching Pattern

Use React Suspense for data fetching with resource caching, error boundaries, and streaming SSR.

Best for: Suspense-first data loading

#react#suspense
typescriptintermediate

useUndoRedo State History Hook

Add undo/redo capability to any state with history tracking, max size limits, and keyboard shortcuts.

Best for: Text editor undo/redo

#react#hooks
typescriptbeginner

Search with Text Highlighting

Build a search component that highlights matching text within results using safe HTML rendering.

Best for: Search results display

#react#search
typescriptintermediate

useInterval Hook

Declarative setInterval hook that handles cleanup and dynamic delay changes safely.

Best for: Polling APIs

#hooks#timer
typescriptbeginner

useTimeout Hook

Declarative setTimeout hook with automatic cleanup and reset capabilities.

Best for: Auto-dismiss notifications

#hooks#timer
typescriptbeginner

useToggle Hook

Simple boolean toggle hook with set, toggle, on, and off functions.

Best for: Modal open/close state

#hooks#state
typescriptintermediate

Controlled Form Component

A reusable controlled form pattern with field-level validation and submission handling.

Best for: Login forms

#form#controlled
typescriptbeginner

NextJS Technique 37

Advanced NextJS pattern 37

Best for: performance

#nextjs#advanced
typescriptintermediate

NextJS Technique 38

Advanced NextJS pattern 38

Best for: performance

#nextjs#advanced
typescriptadvanced

NextJS Technique 39

Advanced NextJS pattern 39

Best for: performance

#nextjs#advanced
typescriptbeginner

NextJS Technique 40

Advanced NextJS pattern 40

Best for: performance

#nextjs#advanced
typescriptintermediate

NextJS Technique 41

Advanced NextJS pattern 41

Best for: performance

#nextjs#advanced
typescriptadvanced

NextJS Technique 42

Advanced NextJS pattern 42

Best for: performance

#nextjs#advanced
typescriptbeginner

NextJS Technique 43

Advanced NextJS pattern 43

Best for: performance

#nextjs#advanced
typescriptintermediate

NextJS Technique 44

Advanced NextJS pattern 44

Best for: performance

#nextjs#advanced
typescriptadvanced

NextJS Technique 45

Advanced NextJS pattern 45

Best for: performance

#nextjs#advanced
typescriptbeginner

NextJS Technique 46

Advanced NextJS pattern 46

Best for: performance

#nextjs#advanced
typescriptintermediate

NextJS Technique 47

Advanced NextJS pattern 47

Best for: performance

#nextjs#advanced
typescriptadvanced

NextJS Technique 48

Advanced NextJS pattern 48

Best for: performance

#nextjs#advanced
typescriptbeginner

NextJS Technique 49

Advanced NextJS pattern 49

Best for: performance

#nextjs#advanced
typescriptintermediate

NextJS Technique 50

Advanced NextJS pattern 50

Best for: performance

#nextjs#advanced
pythonadvanced

Build a ReAct Agent Loop

Implement a reasoning-action loop for an AI agent that uses tools iteratively.

Best for: AI agents

#ai#agent
pythonadvanced

LangChain ReAct Agent Pattern

Implement a ReAct (Reason+Act) agent that thinks step-by-step before calling tools.

Best for: reasoning agents

#langchain#react