Skip to content

Instantly share code, notes, and snippets.

View Ritek's full-sized avatar

Wojciech Rithaler Ritek

View GitHub Profile
@Ritek
Ritek / UseActionState.tsx
Created November 13, 2025 08:42
TS typed useActionState
type FormState = {
name: string;
};
function Form(props: Props) {
async function action(_: FormState, formData: FormData): Promise<FormState> {
const name = formData.get("name") as string;
const surname = formData.get("surname") as string;
console.log({ name, surname });

React TS Patterns

Popular patterns list

  • Compound Components
  • Controlled vs Uncontrolled Components
  • Headless Components (Logic Hooks + UI Primitives)
  • Context + Hooks API Pattern
  • Slot / As-Child Pattern
  • Config Objects / Options API
@Ritek
Ritek / IterableDeque.ts
Created September 4, 2025 00:39
Iterable Deque implementation using TS generic classes
class DequeNode<T = any> {
value: T;
prev: DequeNode<T> | null;
next: DequeNode<T> | null;
constructor(value: T, prev: DequeNode<T> | null = null, next: DequeNode<T> | null = null) {
this.value = value;
this.prev = prev;
this.next = next;
}
@Ritek
Ritek / Trampolining.ts
Created September 3, 2025 22:50
Example of trampolining in TS
function accumulateRecursive(numbers: number[], accumulator: number = 0) {
if (numbers.length === 0) {
return accumulator;
}
const lastIndex = numbers.length - 1;
return accumulateRecursive(numbers.slice(0, lastIndex), accumulator += numbers[lastIndex])
}
@Ritek
Ritek / Server.js
Created August 24, 2025 18:35
Basic Express.js (v5) server for serving React SPA
import express from "express";
import path from "path";
import { fileURLToPath } from "url";
import { dirname } from "path";
const PORT = 8080;
const STATIC_DIR_PATH = "dist";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);