REFACTORING: ScriptEditor (#560)

This commit is contained in:
Aleksei Bezrodnov
2023-06-03 19:55:25 +02:00
committed by GitHub
parent 886f402a43
commit 99954ebd1e
11 changed files with 695 additions and 491 deletions
+19 -1
View File
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react";
import { useCallback, useEffect, useState } from "react";
/** Hook that returns a function for the component. Optionally set an interval to rerender the component.
* @param autoRerenderTime: Optional. If provided and nonzero, used as the ms interval to automatically call the rerender function.
@@ -13,3 +13,21 @@ export function useRerender(autoRerenderTime?: number) {
}, []);
return rerender;
}
export function useBoolean(initialValue = false) {
const [value, setValue] = useState(initialValue);
const toggle = useCallback(() => {
setValue((old) => !old);
}, []);
const on = useCallback(() => {
setValue(true);
}, []);
const off = useCallback(() => {
setValue(false);
}, []);
return [value, { toggle, on, off }] as const;
}