Skip to content

I'm confused regarding combining external parameters and defineQuery #144

Closed Answered by posva
marpe asked this question in Questions
Discussion options

You must be logged in to vote

You don't need useRouteParams() but you need to adapt key so that deckId is a reactive value instead of a plain one. In the first example you need to pass route.params.deckId. route is reactive but deckId is just a string primitive once read

export const useDeck = defineQuery(() => {
  const deckId = useRoute("decks-deckId");
  const result = useQuery({
    key: () => ["decks", { deckId: Number(route.params.deckId) }],
    query: () => useRequestFetch()(`/api/decks?deckId=${deckId}`).then(decks => {
      return decks.find(d => d.id === deckId);
    }) as Promise<(Deck & { cardCount: number }) | undefined>,
  });
  return {
    ...result,
    deckId,
  }
});

You can find more about the re…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@posva
Comment options

@marpe
Comment options

@marpe
Comment options

Answer selected by posva
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #143 on December 23, 2024 07:53.