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:60

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:38

Registers a document-level keydown listener that invokes callback when the Escape key is pressed. The latest callback is always called via an internal ref, so callers may pass a fresh closure each render without re-registering the listener.

Parameters

callback

(() => void) | undefined

Invoked on Escape; pass undefined to do nothing.

Returns

void


useFetched()

useFetched<T>(promise): T | undefined

Defined in: extension/data/util/ui/hooks.ts:74

React hook that resolves a promise and returns its value.

Type Parameters

T

T

Parameters

promise

Promise<T>

Returns

T | undefined


useSaveRef()

useSaveRef(saveRef, handleSave): void

Defined in: extension/data/util/ui/hooks.ts:19

Wires a child component’s save handler up to a parent-provided SaveRef so the parent (e.g. a config overlay’s footer button) can trigger the save. The latest handleSave is always invoked via an internal ref, so callers may pass a fresh closure each render without re-running the effect.

Parameters

saveRef

SaveRef | undefined

The parent’s ref to populate, or undefined to opt out.

handleSave

() => void

The component’s current save handler.

Returns

void


useSetting()

useSetting<T>(moduleName, settingName, defaultValue): T

Defined in: extension/data/util/ui/hooks.ts:102

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.

Type Aliases

SaveRef

SaveRef = object

Defined in: extension/data/util/ui/hooks.ts:9

A ref whose .current a parent calls to trigger a child’s save.

Properties

current

current: (() => void) | null

Defined in: extension/data/util/ui/hooks.ts:9