MCPcopy
hub / github.com/GitbookIO/gitbook / reactToString

Function reactToString

packages/gitbook/src/intl/translate.tsx:60–78  ·  view source on GitHub ↗
(el: React.ReactNode)

Source from the content-addressed store, hash-verified

58}
59
60function reactToString(el: React.ReactNode): string {
61 if (typeof el === 'string' || typeof el === 'number' || typeof el === 'boolean') {
62 return `${el}`;
63 }
64
65 if (el === null || el === undefined) {
66 return '';
67 }
68
69 if (Array.isArray(el)) {
70 return el.map(reactToString).join('');
71 }
72
73 if (typeof el === 'object' && 'props' in el) {
74 return el.props.children.map(reactToString).join('');
75 }
76
77 throw new Error(`Unsupported type ${typeof el}`);
78}

Callers 1

tStringFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected