Skip to content

Instantly share code, notes, and snippets.

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