Skip to content
This repository was archived by the owner on Jan 10, 2024. It is now read-only.

Commit cc5c8da

Browse files
author
Matt Rothenberg
committed
fix: guard against null file name
1 parent 4b6090c commit cc5c8da

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/blocks/example-file-block/index.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import "./index.css";
77

88
export default function (props: FileBlockProps) {
99
const { context, content, metadata, onUpdateMetadata } = props;
10-
const language = getLanguageFromFilename(context.file);
10+
const language = Boolean(context.file)
11+
? getLanguageFromFilename(context.file)
12+
: "N/A";
1113

1214
useTailwindCdn();
1315

@@ -17,7 +19,14 @@ export default function (props: FileBlockProps) {
1719
File: {context.path} {language}
1820
</p>
1921
<div className="py-6">
20-
Metadata example: this button has been clicked <button onClick={() => onUpdateMetadata({ number: (metadata.number || 0) + 1 })}>{metadata.number || 0} times</button>
22+
Metadata example: this button has been clicked{" "}
23+
<button
24+
onClick={() =>
25+
onUpdateMetadata({ number: (metadata.number || 0) + 1 })
26+
}
27+
>
28+
{metadata.number || 0} times
29+
</button>
2130
</div>
2231
<pre className="p-4 text-gray-600">{content}</pre>
2332
</div>

0 commit comments

Comments
 (0)