react-native-markdown-renderer
Version:
Markdown renderer for react-native, with CommonMark spec support + adds syntax extensions & sugar (URL autolinking, typographer).
23 lines (19 loc) • 562 B
text/typescript
import type { ReactElement } from 'react';
interface SplitResult {
textNodes: ReactElement[];
nonTextNodes: ReactElement[];
}
export default function splitTextNonTextNodes(children: ReactElement[]): SplitResult {
return children.reduce<SplitResult>(
(acc, curr) => {
const displayName = (curr.type as { displayName?: string })?.displayName;
if (displayName === 'Text') {
acc.textNodes.push(curr);
} else {
acc.nonTextNodes.push(curr);
}
return acc;
},
{ textNodes: [], nonTextNodes: [] }
);
}