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.

686 B
Raw Blame
/* Copyright 2026 Marimo. All rights reserved. */
import { useCallback, useState } from "react";

type Event = Partial<Pick<React.MouseEvent, "stopPropagation">>;

export function useBoolean(initialState: boolean) {
  const [state, setState] = useState(initialState);

  return [
    state,
    {
      setTrue: useCallback((evt?: Event) => {
        evt?.stopPropagation?.();
        setState(true);
      }, []),
      setFalse: useCallback((evt?: Event) => {
        evt?.stopPropagation?.();
        setState(false);
      }, []),
      toggle: useCallback((evt?: Event) => {
        evt?.stopPropagation?.();
        setState((prev) => !prev);
      }, []),
    },
  ] as const;
}