Skip to content

Commit

Permalink
Merge pull request #632 from arorachakit/add-bridge-options-to-Storyb…
Browse files Browse the repository at this point in the history
…lokStory

add bridge options to StoryblokStory
  • Loading branch information
fgiuliani authored Jul 17, 2023
2 parents d0192dd + b2f063e commit 2318cf0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,10 @@ export async function fetchData() {
}
```
`StoryblokStory` keeps the state for thet story behind the scenes and uses `StoryblokComponent` to render the route components dynamically, using the list of components loaded during the initialization inside the `storyblokInit` function. You can use the `StoryblokComponent` inside the components to redner the nested components dynamically.
`StoryblokStory` keeps the state for thet story behind the scenes and uses `StoryblokComponent` to render the route components dynamically, using the list of components loaded during the initialization inside the `storyblokInit` function. You can use the `StoryblokComponent` inside the components to render the nested components dynamically. You can also pass bridge options to `StoryblokStory` using the prop `bridgeOptions`.
```js
<StoryblokStory story={data.story} bridgeOptions={bridgeOptions} />
```
> Note: To use this approach (with `getStoryblokApi`), you need to include the `apiPlugin` module when calling `storyblokInit` function. If you don't use `apiPlugin`, you can use your preferred method or function to fetch your data.
Expand Down
7 changes: 4 additions & 3 deletions lib/story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
import React, { forwardRef } from "react";
import { useStoryblokState } from "./common/client";
import StoryblokComponent from "./common/storyblok-component";
import { ISbStoryData } from "./types";
import { ISbStoryData, StoryblokBridgeConfigV2 } from "./types";

interface StoryblokStoryProps {
story: ISbStoryData;
bridgeOptions: StoryblokBridgeConfigV2;
[key: string]: unknown;
}

const StoryblokStory = forwardRef<HTMLElement, StoryblokStoryProps>(
({ story, ...restProps }, ref) => {
({ story, bridgeOptions, ...restProps }, ref) => {
if (typeof story.content === "string") {
story.content = JSON.parse(story.content);
}
story = useStoryblokState(story);
story = useStoryblokState(story, bridgeOptions);
return <StoryblokComponent ref={ref} blok={story.content} {...restProps} />;
}
);
Expand Down

0 comments on commit 2318cf0

Please sign in to comment.