GraphContentWide: type guard with conditionals
@@ -24,8 +24,7 @@ function GraphContentWideInner(
return (
<Box {...rest}>
{post.contents.map((content: Content, i) => {
- switch (Object.keys(content)[0]) {
- case 'text':
+ if ('text' in content) {
return (
<TextContent
key={i}
@@ -35,9 +34,9 @@ function GraphContentWideInner(
content={content}
/>
);
- case 'code':
+ } else if ('code' in content) {
return <CodeContent key={i} content={content} />;
- case 'reference':
+ } else if ('reference' in content) {
const { link } = referenceToPermalink(content as ReferenceContent);
return (
<PermalinkEmbed
@@ -47,7 +46,7 @@ function GraphContentWideInner(
showOurContact={showOurContact}
/>
);
- case 'url':
+ } else if ('url' in content) {
return (
<Box
key={i}
@@ -65,18 +64,14 @@ function GraphContentWideInner(
/>
</Box>
);
- case 'mention':
+ } else if ('mention' in content) {
const first = i => i === 0;
- return (
- <Mention
+ return (<Mention
key={i}
first={first(i)}
ship={content.mention}
api={api}
- />
- );
- default:
- return null;
+ />);
}
})}
</Box>
