Skip to content

Instantly share code, notes, and snippets.

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