Code Snippets Library

Production-ready code snippets for modern web development. Search, copy, and use in your projects.

React useLocalStorage Hook

A custom hook that persists state to localStorage with automatic serialization.

import { useState, useEffect } from 'react'
ReactTypeScriptreacthook

React useDebounce Hook

A hook that delays updating a value until a specified time has passed since the last change.

import { useState, useEffect } from 'react'
ReactTypeScriptreacthook

React useFetch Hook

A generic data fetching hook with loading and error states.

import { useState, useEffect } from 'react'
ReactTypeScriptreacthook

React useClickOutside Hook

Detects clicks outside a referenced element to close dropdowns or modals.

import { useEffect, useRef } from 'react'
ReactTypeScriptreacthook

React Toggle Component

An accessible toggle switch component with smooth animation.

import { useState } from 'react'
ReactTypeScriptreactcomponent

React Modal Component

A reusable modal dialog with backdrop, keyboard handling, and portal rendering.

import { useEffect, type ReactNode } from 'react'
import { createPortal } from 'react-dom'
ReactTypeScriptreactcomponent

React useInfiniteScroll Hook

A hook that triggers a callback when the user scrolls near the bottom of the page.

import { useEffect, useCallback } from 'react'
ReactTypeScriptreacthook

React Dark Mode Toggle

A hook and component for toggling dark mode with system preference detection.

import { useState, useEffect } from 'react'
ReactTypeScriptreactdark mode

Next.js API Route Handler

A typed API route handler with request validation and error handling.

import { NextRequest, NextResponse } from 'next/server'
Next.jsTypeScriptnextjsapi

Next.js Auth Middleware

Middleware that protects routes by checking for an authentication token.

import { NextRequest, NextResponse } from 'next/server'
Next.jsTypeScriptnextjsmiddleware

Next.js Dynamic Metadata

Generate dynamic SEO metadata based on page params and fetched data.

import type { Metadata } from 'next'
Next.jsTypeScriptnextjsseo

Next.js Server Action Form

A form that uses server actions for submission with validation.

'use server'
Next.jsTypeScriptnextjsform

Next.js Sitemap Generator

Automatically generate a sitemap.xml from static and dynamic routes.

import type { MetadataRoute } from 'next'
Next.jsTypeScriptnextjssitemap

TypeScript Utility Types

Useful custom utility types for everyday TypeScript development.

// Make specific keys optional
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
TypeScriptTypeScripttypescripttypes

TypeScript Enum Alternatives

Type-safe alternatives to enums using const objects and union types.

// Instead of: enum Status { Active, Inactive, Pending }
// Use a const object:
TypeScriptTypeScripttypescriptenum

TypeScript Type Guards

Runtime type narrowing functions for safe type checking.

// User-defined type guard
interface Dog { kind: 'dog'; bark(): void }
TypeScriptTypeScripttypescripttype guard

TypeScript Zod Validation

Runtime schema validation with automatic TypeScript type inference.

import { z } from 'zod'
TypeScriptTypeScripttypescriptzod

TypeScript Generic API Client

A type-safe, reusable HTTP client with generics and interceptors.

interface ApiResponse<T> {
  data: T
TypeScriptTypeScripttypescriptapi

CSS Glass Morphism Effect

A frosted glass effect using backdrop-filter for modern UI cards.

.glass-card {
  background: rgba(255, 255, 255, 0.08);
CSS / TailwindCSScssglass

CSS Gradient Text

Apply gradient colors to text using background-clip for eye-catching headings.

.gradient-text {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
CSS / TailwindCSScssgradient

Tailwind Responsive Grid Layout

A responsive grid system that adapts from 1 column on mobile to 4 columns on desktop.

<!-- Responsive card grid -->
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6 p-6">
CSS / TailwindHTMLtailwindgrid

CSS Smooth Scroll

Enable smooth scrolling behavior with CSS and scroll-snap for sections.

/* Global smooth scrolling */
html {
CSS / TailwindCSScssscroll

Node.js Express Middleware

A set of reusable Express middleware functions for logging, error handling, and CORS.

import express, { Request, Response, NextFunction } from 'express'
Node.jsTypeScriptnodejsexpress

Node.js JWT Authentication

JWT token generation and verification middleware for API authentication.

import jwt from 'jsonwebtoken'
import type { Request, Response, NextFunction } from 'express'
Node.jsTypeScriptnodejsjwt

Node.js Rate Limiter

An in-memory rate limiter middleware to protect APIs from abuse.

import type { Request, Response, NextFunction } from 'express'
Node.jsTypeScriptnodejsrate limit

Node.js File Upload with Multer

Handle file uploads with validation for type, size, and storage configuration.

import multer from 'multer'
import path from 'path'
Node.jsTypeScriptnodejsfile

Laravel API Resource

Transform Eloquent models into structured JSON API responses.

<?php
LaravelPHPlaravelapi

Laravel Custom Middleware

A middleware that checks user roles and logs request details.

<?php
LaravelPHPlaravelmiddleware

Laravel Eloquent Query Scopes

Reusable query scopes for cleaner and more expressive Eloquent queries.

<?php
LaravelPHPlaraveleloquent

Laravel Job Queue

A queueable job for handling time-consuming tasks asynchronously.

<?php
LaravelPHPlaravelqueue

Have a Project in Mind?

Let's discuss how we can bring your idea to life. From initial concept to production-ready product — we've got you covered.

or book a free call