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/course/configuration/state-helpers.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { useState } from "react";
7
8
export function useConfirmation<T extends any[], U>(
9
confirmation: (...args: T) => U,
10
init = false,
11
): [boolean, (...args: T) => U, () => void, () => void] {
12
const [confirmation_is_open, set_confirmation] = useState(init);
13
function confirm(...args: T): U {
14
set_confirmation(false);
15
return confirmation(...args);
16
}
17
function close_confirmation() {
18
set_confirmation(false);
19
}
20
function open_confirmation() {
21
set_confirmation(true);
22
}
23
return [confirmation_is_open, confirm, open_confirmation, close_confirmation];
24
}
25
26