Skip to content

Commit

Permalink
feat: add TypeScript support
Browse files Browse the repository at this point in the history
  • Loading branch information
schabibi1 committed Jul 22, 2022
1 parent fa4deac commit a872ac9
Show file tree
Hide file tree
Showing 10 changed files with 9,490 additions and 27,044 deletions.
14 changes: 0 additions & 14 deletions lib/index.js

This file was deleted.

22 changes: 22 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useEffect, useState } from "react";
import { useStoryblokBridge as useSbBridge } from "@storyblok/react";
export { useStoryblokBridge, storyblokInit, apiPlugin, StoryblokComponent, storyblokEditable, useStoryblokApi, getStoryblokApi } from "@storyblok/react";
import type {
SbGatsbyStory,
StoryblokBridgeConfigV2
} from './types'

export function useStoryblokState(originalStory: SbGatsbyStory,
bridgeOptions: StoryblokBridgeConfigV2 = {}) {
if (typeof originalStory.content === "string") originalStory.content = JSON.parse(originalStory.content);

let [story, setStory] = useState(originalStory);
useEffect(() => {
useSbBridge(story.internalId, (newStory: SbGatsbyStory) => setStory(newStory), bridgeOptions);
}, []);

return story;
}

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

0 comments on commit a872ac9

Please sign in to comment.