Created
February 5, 2022 15:25
-
-
Save kazuooooo/0e24f69c5db19662911ddbc23eb7c0b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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