N

react

namespace react

Functions

F

shallow<T>(previous: T, next: T): boolean

Compares two values one level deep: each own key, or each entry of a Map, Set or array, by Object.is. Pass it as isEqual.

F

useShallow<S, U>(selector: (state: S) => U): (state: S) => U

Wraps a selector so a result shallow-equal to its last one returns the last one, which skips the re-render.

F

filterComponents<P = any>(tree: any, match: ComponentMatch<P>): ReactElement<P, string | JSXElementConstructor<any>>[]

Finds every element in a rendered tree that a component name or predicate picks, walking only props and children.

Returns

Every matching element, outermost first.

F

filterInTree<T = any>(root: any, predicate: TreePredicate, options?: TreeSearchOptions): T[]

Finds every node in a React element or fiber tree a predicate matches, searching only downward. Start from an element, a fiber, or a class instance's _reactInternals.

Returns

Every match, in visiting order.

F

findComponent<P = any>(tree: any, match: ComponentMatch<P>): ReactElement<P, string | JSXElementConstructor<any>> | undefined

Finds the first element in a rendered tree that a component name or predicate picks, walking only props and children.

Returns

The first matching element, or undefined when none matches.

F

findInTree<T = any>(root: any, predicate: TreePredicate, options?: TreeSearchOptions): T | undefined

Finds the first node in a React element or fiber tree a predicate matches, searching only downward. Start from an element, a fiber, or a class instance's _reactInternals.

Returns

The first match, or undefined when none matches.

Types

Picks an element: a component name, matched against its displayName or name through memo and forwardRef wrappers (or a host type such as RCTView), or a predicate on the element.

A node in an object graph, such as a React tree. Discord's trees carry no static types, so a predicate reads them unchecked.

Tests one node of a tree; a truthy result is a match.

How a tree search descends.