NuxtN
Nuxtβ€’17mo ago
ParadoX

How to create a stateful composable that uses useState?

So I am refactoring my app and I am replacing pinia stores with composables. If I want a global state that is shared with all instances of that composable, I need to define this ref outside of the exported function. Like this:

const globalState = ref();
export default () => { 
      // [...]
      return {
        // [...]
        state: readonly(globalState),
    };
}


However, if I want to use useState, I cannot do that outside of the composable function. What now? πŸ€”
Was this page helpful?