moderator-toolbox-nxg-for-reddit / util/ui/hooks
util/ui/hooks¶
Functions¶
useBusyState()¶
useBusyState(): [
boolean, <T>(operation) =>Promise<T>]
Defined in: extension/data/util/ui/hooks.ts:94
Tracks a single in-flight async operation behind a boolean busy flag.
Returns the current busy state plus a runBusy wrapper that sets the flag
true before awaiting the supplied operation and resets it in a finally, so
the flag is always cleared even if the operation throws. The flag is reset
before runBusy’s returned promise resolves, so any follow-up work the caller
chains after await runBusy(...) runs with the flag already cleared.
Returns¶
[boolean, <T>(operation) => Promise<T>]
A [busy, runBusy] tuple.
useEscapeKey()¶
useEscapeKey(
callback):void
Defined in: extension/data/util/ui/hooks.ts:64
Registers an Escape handler in a shared stack so a single Escape press invokes
only the top-most active dialog’s callback, not every mounted dialog’s. The
latest callback is always called via an internal ref, so callers may pass a
fresh closure each render without re-registering.
Parameters¶
callback¶
(() => void) | undefined
Invoked on Escape when this is the top-most active handler;
pass undefined to opt out (Escape falls through to the dialog beneath).
Returns¶
void
useFetched()¶
useFetched<
T>(promise):T|undefined
Defined in: extension/data/util/ui/hooks.ts:134
React hook that resolves a promise and returns its value. Only the promise passed on the first render is observed; later renders’ promises are ignored.
Type Parameters¶
T¶
T
Parameters¶
promise¶
Promise<T>
Returns¶
T | undefined
useMountEffect()¶
useMountEffect(
effect):void
Defined in: extension/data/util/ui/hooks.ts:113
Runs effect once after the first render, and its cleanup on unmount. For effects that
deliberately capture their first-render props and callbacks (initial options, onMount
handoffs, one-shot fetches) and must not re-run when those identities change.
Parameters¶
effect¶
EffectCallback
The side-effect to run; may return a cleanup function.
Returns¶
void
useMountLayoutEffect()¶
useMountLayoutEffect(
effect):void
Defined in: extension/data/util/ui/hooks.ts:124
Layout-effect variant of useMountEffect: runs synchronously after the first render’s DOM mutations, before paint (e.g. initial positioning and focus).
Parameters¶
effect¶
EffectCallback
The side-effect to run; may return a cleanup function.
Returns¶
void
useSetting()¶
useSetting<
T>(moduleName,settingName,defaultValue):T
Defined in: extension/data/util/ui/hooks.ts:162
React hook that reads a Toolbox setting from the store.
Type Parameters¶
T¶
T
The setting value’s type.
Parameters¶
moduleName¶
string
Module ID that owns the setting.
settingName¶
string
Key of the setting.
defaultValue¶
T
Fallback returned while the setting is unset or settings data hasn’t loaded yet.
Returns¶
T
The setting’s current value, or the fallback.
useTriggerRef()¶
useTriggerRef(
triggerRef,handler):void
Defined in: extension/data/util/ui/hooks.ts:20
Wires a child component’s handler up to a parent-provided TriggerRef so the
parent (e.g. a config overlay’s footer button) can trigger it - a save, or any
other footer-driven action such as “add new” or “import”.
The latest handler is always invoked via an internal ref, so callers may
pass a fresh closure each render without re-running the effect.
Parameters¶
triggerRef¶
TriggerRef | undefined
The parent’s ref to populate, or undefined to opt out.
handler¶
() => void
The component’s current handler for the action.
Returns¶
void
Type Aliases¶
TriggerRef¶
TriggerRef =
object
Defined in: extension/data/util/ui/hooks.ts:9
A ref whose .current a parent calls to trigger a child’s action (save, add, import).
Properties¶
current¶
current: (() =>
void) |null
Defined in: extension/data/util/ui/hooks.ts:9