Skip to content

Class: BoundHooks ​

BoundHooks is a utility class for React hooks, with plugin scoping automatically supplied. An instance is available on instances of BdApi.

Extends ​

Properties ​

useForceUpdate ​

useForceUpdate: () => [number, ActionDispatch<any>]

Creates a hook that forces a re-render when called.

Returns ​

[number, ActionDispatch<any>]

Inherited from ​

BaseHooks.useForceUpdate


useStateFromStores ​

useStateFromStores: <T>(stores, factory, deps?, isStateEqual) => T

Subscribes to one or more stores and re-computes a value when they change, causing a re-render. A store is anything with an addChangeListener and removeChangeListener method, such as Discord's Flux stores or BdApi.Utils.Store.

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterTypeDescription
storesStoreType | StoreType[]The store(s) to subscribe to
factory() => TA function that computes the value to return when stores change
deps?DependencyListAn optional dependency list that controls when the factory function is updated
isStateEqual?true | ((oldState, newState) => boolean)An optional function that allows for skipping re-renders if the state hasn't changed, or true to use a shallow equality check

Returns ​

T

Inherited from ​

BaseHooks.useStateFromStores

Methods ​

useData() ​

useData<T>(key): T

Retrieves data from storage and automatically re-renders when it changes.

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterTypeDescription
keystringThe key of the data to retrieve

Returns ​

T

The current value of the data with the given key, or undefined if it doesn't exist