CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/app-framework/toggle-hook.ts
Views: 687
1
import { useState } from "react";
2
3
// This is a simple boolean toggle.
4
export default function useToggle(
5
init: boolean = false
6
): [boolean, () => void] {
7
const [val, setVal] = useState(init);
8
const toggle = () => setVal(!val);
9
return [val, toggle];
10
}
11
12