typescript

typescript
import { FixedSizeList as List } from 'react-window'
import AutoSizer from 'react-virtualized-auto-sizer'
import { Post } from '@/types'
import { PostCard } from './PostCard'

interface VirtualizedPostListProps {

Virtual scrolling for large lists with react-window

react performance virtual-scrolling
by Maya Patel 1 tab
typescript
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import crypto from 'node:crypto';

const s3 = new S3Client({ region: process.env.AWS_REGION });

Pre-signed S3 upload from the browser

aws s3 uploads
by Mateo Rodriguez 1 tab
typescript
import React, { createContext, useContext, useEffect, useState, ReactNode } from 'react'

type Theme = 'light' | 'dark'

interface ThemeContextType {
  theme: Theme

Dark mode with Tailwind and localStorage persistence

react tailwind dark-mode
by Maya Patel 3 tabs
typescript
import { WebSocketServer } from 'ws';
import type WebSocket from 'ws';

type ClientState = { topics: Set<string> };
const state = new WeakMap<WebSocket, ClientState>();

WebSocket server with topic subscriptions (ws)

node realtime websockets
by Mateo Rodriguez 1 tab
typescript
export interface Cursor {
  createdAt: string;
  id: string;
}

export function encodeCursor(c: Cursor): string {

Cursor Pagination for a REST List Endpoint with a Typed Fetch Client

typescript express rest
by codesnips 3 tabs
typescript
import { useState } from 'react'
import {
  DndContext,
  closestCenter,
  KeyboardSensor,
  PointerSensor,

Drag and drop with dnd-kit

react drag-drop dnd-kit
by Maya Patel 1 tab
typescript
import { useForm } from 'react-hook-form';
import { z } from 'zod';
import { zodResolver } from '@hookform/resolvers/zod';

const Schema = z.object({ title: z.string().min(2).max(120) });
type Form = z.infer<typeof Schema>;

React Hook Form + Zod resolver

react forms typescript
by Mateo Rodriguez 1 tab
typescript
export const Flags = {
  NEW_EDITOR: 'new_editor',
  FAST_SEARCH: 'fast_search',
  BILLING_V2: 'billing_v2'
} as const;

Feature flags with a typed registry

typescript product
by Mateo Rodriguez 1 tab
typescript
import type { RequestHandler } from 'express';
import crypto from 'node:crypto';

export function weakEtag(value: string) {
  const hash = crypto.createHash('sha1').update(value).digest('hex');
  return `W/"${hash}"`;

ETag + conditional GET for read-heavy endpoints

http performance caching
by Mateo Rodriguez 1 tab
typescript
import argon2 from 'argon2';

export async function hashPassword(password: string) {
  return argon2.hash(password, { type: argon2.argon2id });
}

Password hashing with Argon2

security auth node
by Mateo Rodriguez 1 tab
typescript
import { withClient } from './pool';

export async function withAdvisoryLock(key: string, fn: () => Promise<void>) {
  const lockId = Array.from(key).reduce((acc, c) => (acc * 31 + c.charCodeAt(0)) >>> 0, 0);
  return withClient(async (client) => {
    const got = await client.query('SELECT pg_try_advisory_lock($1) AS got', [lockId]);

Postgres advisory lock for one-at-a-time work

postgres concurrency reliability
by Mateo Rodriguez 1 tab
typescript
import { Suspense } from 'react'
import { useSuspenseQuery } from '@tanstack/react-query'
import { useParams } from 'react-router-dom'
import api from '@/services/api'
import { Post } from '@/types'
import { ErrorBoundary } from '@/components/ErrorBoundary'

React Suspense for data fetching

react suspense async-loading
by Maya Patel 1 tab