typescript

typescript
import { ReactNode, useEffect, useState } from 'react'
import { createPortal } from 'react-dom'

interface PortalProps {
  children: ReactNode
  container?: Element

React portals for rendering outside component tree

react portals dom
by Maya Patel 2 tabs
typescript
import { Link, useLocation, useMatches } from 'react-router-dom'

interface BreadcrumbMatch {
  pathname: string
  handle?: {
    crumb?: (data?: any) => string

Breadcrumb navigation from React Router

react react-router navigation
by Maya Patel 2 tabs
typescript
import { NextResponse } from 'next/server';
import { z } from 'zod';

const Body = z.object({ name: z.string().min(2).max(80) });

function getUserId(req: Request) {

Next.js Route Handler with auth guard

nextjs react api
by Mateo Rodriguez 1 tab
typescript
export interface Todo {
  id: string;
  title: string;
  done: boolean;
}

Optimistic Todo Toggling in React with Rollback via useReducer

javascript typescript react
by codesnips 3 tabs
typescript
import Busboy from 'busboy';
import type { Request, Response } from 'express';

export function upload(req: Request, res: Response) {
  const bb = Busboy({ headers: req.headers, limits: { fileSize: 10 * 1024 * 1024 } });
  let bytes = 0;

Multipart upload streaming (busboy)

node uploads streams
by Mateo Rodriguez 1 tab
typescript
import React, { createContext, useContext, useState, ReactNode } from 'react'

interface TabsContextType {
  activeTab: string
  setActiveTab: (tab: string) => void
}

Compound components pattern for flexible APIs

react patterns components
by Maya Patel 2 tabs
typescript
import { initTRPC } from '@trpc/server';
import { z } from 'zod';

const t = initTRPC.context<{ userId?: string }>().create();
const authed = t.middleware(({ ctx, next }) => {
  if (!ctx.userId) throw new Error('UNAUTHORIZED');

tRPC router pattern for type-safe APIs

typescript trpc api
by Mateo Rodriguez 1 tab
typescript
import http from 'node:http';

export function setupGracefulShutdown(server: http.Server, opts?: { timeoutMs?: number }) {
  const timeoutMs = opts?.timeoutMs ?? 10_000;
  const sockets = new Set<import('node:net').Socket>();
  let isShuttingDown = false;

Graceful shutdown for Node HTTP servers

node reliability deploy
by Mateo Rodriguez 1 tab
typescript
export async function fetchWithTimeout(input: RequestInfo, init: RequestInit & { timeoutMs?: number } = {}) {
  const controller = new AbortController();
  const timeoutMs = init.timeoutMs ?? 5_000;

  const t = setTimeout(() => controller.abort(), timeoutMs);
  try {

HTTP client timeout with AbortController (fetch)

node http reliability
by Mateo Rodriguez 1 tab
typescript
import { Link } from 'react-router-dom'
import { useQueryClient } from '@tanstack/react-query'
import api from '@/services/api'
import { PostId } from '@/types'

interface PostLinkProps {

Prefetching data on hover for instant navigation

react performance prefetching
by Maya Patel 1 tab
typescript
import React from 'react'

interface SkeletonProps {
  width?: string | number
  height?: string | number
  className?: string

Skeleton screens for better perceived performance

react ux performance
by Maya Patel 3 tabs
typescript
import { useMutation, useQueryClient } from '@tanstack/react-query';

type Snip = { id: string; liked: boolean; likesCount: number };

export function useToggleLike(snipId: string) {
  const qc = useQueryClient();

React Query optimistic update for likes

react typescript frontend
by Mateo Rodriguez 1 tab