(el: React.ReactNode)
| 58 | } |
| 59 | |
| 60 | function 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 | } |