Skip to content

Commit

Permalink
feat: use the unique key in useState too
Browse files Browse the repository at this point in the history
  • Loading branch information
Dawntraoz committed Nov 28, 2022
1 parent 497de1d commit a04841f
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/src/runtime/composables/useAsyncStoryblok.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export const useAsyncStoryblok = async (
apiOptions = {},
bridgeOptions = {}
) => {
const story = useState(url, () => null);
const uniqueKey = `${JSON.stringify(apiOptions)}${url}`;
const story = useState(`${uniqueKey}-state`, () => null);
const storyblokApiInstance = useStoryblokApi();

onMounted(() => {
Expand All @@ -19,10 +20,8 @@ export const useAsyncStoryblok = async (
}
});

const hash = JSON.stringify(apiOptions);

const { data } = await useAsyncData(
`${hash}-${url}`,
`${uniqueKey}-asyncdata`,
async () => await storyblokApiInstance.get(`cdn/stories/${url}`, apiOptions)
);
story.value = data.value.data.story;
Expand Down

0 comments on commit a04841f

Please sign in to comment.