Skip to main content

react

reactNodeToText()

function reactNodeToText(node): string;

Defined in: src/utils/react/react.ts:27

Converts a React node to its string representation by extracting all text content.

Parameters

ParameterTypeDescription
nodeReactNodeThe React node to convert to text

Returns

string

The text content of the node. Returns an empty string if the node is null, undefined, or boolean.

Example

reactNodeToText("Hello") // "Hello"
reactNodeToText(42) // "42"
reactNodeToText(<div>Hello World</div>) // "Hello World"
reactNodeToText([<span>A</span>, <span>B</span>]) // "AB"