mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-06 07:37:56 +02:00
REFACTORING: ScriptEditor (#560)
This commit is contained in:
committed by
GitHub
parent
886f402a43
commit
99954ebd1e
+19
-1
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user