Skip to content

Examples of using Pinia Colada in Pinia stores? #214

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

You must be logged in to vote

For that you can use:

import { defineQuery, useQuery } from '@pinia/colada'
import { useRouteQuery } from '@vueuse/router'
import { searchContacts } from '@/api/contacts'

export const useContactSearch = defineQuery(() => {
  const searchText = useRouteQuery('search', '', { mode: 'push' })
  const { ...query } = useQuery({
    key: () => ['contacts-search', { searchText: searchText.value }],
    query: async ({ signal }) => searchContacts(searchText.value, {}, { signal }),
    staleTime: 0,
    // avoids flickering when the search text changes
    placeholderData: (previousData) => previousData,
    // avoids displaying the "Loading..." too quickly
    // makes your app look more responsive

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
7 replies
@onmax
Comment options

@onmax
Comment options

@brandonleichty
Comment options

@posva
Comment options

Answer selected by brandonleichty
@brandonleichty
Comment options

@posva
Comment options

@brandonleichty
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants