Skip to content

Instantly share code, notes, and snippets.

View cvoege's full-sized avatar

Colton Voege cvoege

View GitHub Profile
@cvoege
cvoege / TypedLocalStorage.ts
Created January 19, 2026 16:10
TypedLocalStorage.ts - Adds typing and validation with zod for your local storage access, discarding corrupted local storage entries and falling back when local storage isn't available
import { useCallback, useEffect, useRef, useState } from "react";
import { z } from "zod";
import { getUniqueId } from "./getUniqueId";
// Some examples
const localStorageValidators = {
auth: z.object({
token: z.string(),
expiresAt: z.iso.datetime(),
}),