Skip to content

Commit 0332b5f

Browse files
authored
Allow multiple text nodes in markdown component (#855)
1 parent 5f57acd commit 0332b5f

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

packages/core/src/components/Markdown.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,34 @@ type MarkdownProps = {
66
style?: StyleProp<ViewStyle>;
77
};
88

9+
const childToString = (child?: React.ReactNode): string => {
10+
if (
11+
typeof child === "undefined" ||
12+
child === null ||
13+
typeof child === "boolean"
14+
) {
15+
return "";
16+
}
17+
18+
if (JSON.stringify(child) === "{}") {
19+
return "";
20+
}
21+
22+
return (child as number | string).toString();
23+
};
24+
925
const Markdown: React.FC<React.PropsWithChildren<MarkdownProps>> = ({
10-
children,
26+
children: childrenProp,
1127
style,
1228
}) => {
29+
const children = React.Children.toArray(childrenProp);
30+
const text = children.map(childToString).join("");
31+
1332
return (
1433
//'body' style applies to all markdown components
1534
//@ts-ignore TS does not like the type of this named style for some reason
1635
<MarkdownComponent style={{ body: StyleSheet.flatten(style) }}>
17-
{children}
36+
{text}
1837
</MarkdownComponent>
1938
);
2039
};

0 commit comments

Comments
 (0)