How to share an indexedDb
Hello friends,
pretty new to nuxt and js/ts, so maybe a trivial question there, forgive me.
How do I instantiate an indexedb and access it through all of my nuxt app ?
Many thanks
30 Replies
Check out localforage. Makes working with IndexedDB a breeze. Pair it with a composable - or a plugin as you have - to achieve your desired result.
here's a modified version using
useState
Thanks you very much, I'll try that !
I didn't know of this return provide syntax
I couldn't use idb in my stores (not found), so I used a composable and it seems to work fine !
Thanks mate
make sure the idb plugin is registered before the store
Sorry I don't know how to check that ^^
you can rename the plugin to
1.{name}.ts
the number prefix dictates the order in which the plugins are registered. if no numbers is specified, the plugins will be registered in alphabetical order.
https://nuxt.com/docs/guide/directory-structure/plugins#registration-orderI saw that, but the stores are in their own folder
can you share a screenshot of your directory structure?
sure !
![No description](https://cdn.answeroverflow.com/1234501564618772512/image.png)
how are the stores registered? Pinia?
yes
wait, are you in ssr mode?
probably so
or is it a SSG site?
I have an hydration stuff to fill the store only on the client
hmmm. since Pinia runs on the server side as well I'm thinking the plugin won't work because you're only registering it on the client side. I'm not sure how the hydration stuff you've got affects Pinia's ssr capabilities
but I get
idb.client.ts
makes sense because it's a browser API