Skip to content

Class: ReactUtils ​

ReactUtils is a utility class for interacting with React internals. An instance is available on BdApi. This is extremely useful for interacting with the internals of the UI.

Properties ​

getInternalInstance ​

getInternalInstance: (node) => Fiber | null

Gets the internal React data of a specified node.

Parameters ​

ParameterTypeDescription
nodeElementNode to get the internal React data from

Returns ​

Fiber | null

Either the found data or undefined


getOwnerInstance ​

getOwnerInstance: (node, options) => any

Attempts to find the "owner" node to the current node. This is generally a node with a stateNode - a class component.

Parameters ​

ParameterTypeDescription
nodeElement | undefinedNode to obtain React instance of
optionsGetOwnerInstanceOptionsOptions for the search

Returns ​

any

The owner instance or undefined if not found


getType ​

getType: <T, P>(elementType) => T

Gets the type of a React component, going through things such as forwardRef and memo

Type Parameters ​

Type Parameter
T extends FC<P>
P

Parameters ​

ParameterType
elementTypeReactElementType<T, P>

Returns ​

T


wrapElement ​

wrapElement: (element) => typeof ReactWrapper

Creates an unrendered React component that wraps HTML elements.

Parameters ​

ParameterTypeDescription
elementElement | Element[]Element or array of elements to wrap

Returns ​

typeof ReactWrapper

Unrendered React component


wrapInHooks ​

wrapInHooks: <T, P>(functionComponent, customPatches) => FunctionComponent<ComponentProps<T>>

Wraps a functional React component to allow it to be created outside of the normal React lifecycle.

Type Parameters ​

Type Parameter
T extends FC<P>
P

Parameters ​

ParameterTypeDescription
functionComponentT | ForwardRefExoticComponent<T> | MemoExoticComponent<T | ForwardRefExoticComponent<T>>The functional component to wrap
customPatchesPartial<PatchedReactHooks>Custom react hooks to use

Returns ​

FunctionComponent<ComponentProps<T>>

The wrapped component

Accessors ​

rootInstance ​

Get Signature ​

get rootInstance(): any

Deprecated ​
Returns ​

any

Methods ​

createNodePatcher() ​

createNodePatcher(): NodePatcher

Creates a NodePatcher instance which is used to patch React nodes

Returns ​

NodePatcher