Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

548 B
Raw Blame
/* Copyright 2026 Marimo. All rights reserved. */

import { useState } from "react";
import { TypedLocalStorage } from "@/utils/storage/typed";

/**
 * React hook to use localStorage
 */
export function useLocalStorage<T>(key: string, defaultValue: T) {
  const storage = new TypedLocalStorage(defaultValue);

  const [storedValue, setStoredValue] = useState<T>(() => {
    return storage.get(key);
  });

  const setValue = (value: T) => {
    setStoredValue(value);
    storage.set(key, value);
  };

  return [storedValue, setValue] as const;
}