Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Commit 5df12d4

Browse files
committed
fix: useStoryblokBridge edge-cases
1 parent dbb7e00 commit 5df12d4

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

lib/index.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ import {
66
StoryData,
77
SbInitResult,
88
Richtext,
9-
StoryblokComponentType
9+
StoryblokComponentType,
1010
} from "./types";
1111

12-
import RichTextResolver from "storyblok-js-client/source/richTextResolver"
12+
import RichTextResolver from "storyblok-js-client/source/richTextResolver";
1313

14-
const resolver = new RichTextResolver;
14+
const resolver = new RichTextResolver();
1515

1616
const bridgeLatest = "https://app.storyblok.com/f/storyblok-v2-latest.js";
1717

18-
export const useStoryblokBridge = <T extends StoryblokComponentType<string> = any>(
18+
export const useStoryblokBridge = <
19+
T extends StoryblokComponentType<string> = any
20+
>(
1921
id: Number,
2022
cb: (newStory: StoryData<T>) => void,
2123
options: StoryblokBridgeConfigV2 = {}
@@ -40,10 +42,9 @@ export const useStoryblokBridge = <T extends StoryblokComponentType<string> = an
4042
window.storyblokRegisterEvent(() => {
4143
const sbBridge: StoryblokBridgeV2 = new window.StoryblokBridge(options);
4244
sbBridge.on(["input", "published", "change"], (event) => {
43-
if (event.action == "input" && event.story.id === id) {
44-
cb(event.story);
45-
} else {
46-
window.location.reload();
45+
if (event.story.id === id) {
46+
if (event.action === "input") cb(event.story);
47+
else window.location.reload();
4748
}
4849
});
4950
});
@@ -73,20 +74,19 @@ export const storyblokInit = (pluginOptions: SbSDKOptions = {}) => {
7374
return result;
7475
};
7576

76-
export const renderRichText = (text: Richtext) : string => {
77-
if (text as any === '') {
78-
return ""
79-
}
80-
else if(!text) {
77+
export const renderRichText = (text: Richtext): string => {
78+
if ((text as any) === "") {
79+
return "";
80+
} else if (!text) {
8181
console.warn(`${text} is not a valid Richtext object. This might be because the value of the richtext field is empty.
8282
83-
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`)
84-
return "";
83+
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`);
84+
return "";
8585
}
86-
return resolver.render(text)
87-
}
86+
return resolver.render(text);
87+
};
8888

89-
export const loadStoryblokBridge = () => loadBridge(bridgeLatest)
89+
export const loadStoryblokBridge = () => loadBridge(bridgeLatest);
9090

9191
// Reexport all types so users can have access to them
9292
export * from "./types";

0 commit comments

Comments
 (0)