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/counter-hook.ts
Views: 687
1
import { useState } from "react";
2
3
// Use this to count up or down. e.g.
4
// const {val: counter_value, inc: inc_counter} = useCounter()
5
export default function useCounter(init: number = 0) {
6
const [val, setVal] = useState(init);
7
const inc = () => setVal(val + 1);
8
const dec = () => setVal(val - 1);
9
return { val, inc, dec };
10
}
11
12