Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/app-framework/counter-hook.ts
1503 views
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