moderator-toolbox-nxg-for-reddit / shared/controls/useAncestorClass

shared/controls/useAncestorClass

Functions

useAncestorClass()

useAncestorClass(target, className, active): void

Defined in: extension/data/shared/controls/useAncestorClass.ts:18

Adds className to target while active is true and the component is mounted, and removes it on unmount or when active becomes false. A no-op when target is null or active is false.

Used by inline Shreddit controls to mark their host shreddit-comment/shreddit-post so the native-control-hiding CSS applies only where a Toolbox replacement is actually rendered - keying the hide off the replacement’s presence rather than off a slot being injected. The class-toggle is a rendering side-effect intrinsically tied to whether the replacement mounted, so it lives in the component’s React lifecycle (effect cleanup removes it) rather than a raw DOM listener.

Parameters

target

Element | null

Element to mark, or null to skip (e.g. before the host resolves).

className

string

CSS class to add while active.

active

boolean

Whether the marker should currently be applied.

Returns

void