Skip to content

Instantly share code, notes, and snippets.

@kazuooooo
Created February 5, 2022 15:28
Show Gist options
  • Save kazuooooo/24c13fd6ca6b7040655186bdab3557a3 to your computer and use it in GitHub Desktop.
Save kazuooooo/24c13fd6ca6b7040655186bdab3557a3 to your computer and use it in GitHub Desktop.
import { collection, getFirestore, query, where } from "firebase/firestore"
import { defineStore } from "pinia"
type ExampleDoc = {
name: string,
age: number
}
export type State = {
queryData: ExampleDoc[] | null,
}
export const useExampleStore = defineStore('expamle', {
state: (): State => {
return {
queryData: null,
}
},
actions: {
async setup() {
// Build query
const store = getFirestore()
const collectionRef = collection(store, 'Examples')
const q = query(collectionRef, where('name', '==', 'wombat'))
// Do the magic
this.sync('queryData', q)
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment