From b4e42b95bdee4dcc869908e9505830cc15e975a8 Mon Sep 17 00:00:00 2001 From: lauramargar <114984466+lauramargar@users.noreply.github.com> Date: Thu, 1 Feb 2024 09:27:34 +0100 Subject: [PATCH] feat(components): create useStore composable (#1401) --- packages/x-components/src/composables/index.ts | 1 + packages/x-components/src/composables/use-store.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 packages/x-components/src/composables/use-store.ts diff --git a/packages/x-components/src/composables/index.ts b/packages/x-components/src/composables/index.ts index 1130f30636..42d0e6fe47 100644 --- a/packages/x-components/src/composables/index.ts +++ b/packages/x-components/src/composables/index.ts @@ -2,3 +2,4 @@ export * from './create-use-device.composable'; export * from './use-$x'; export * from './use-register-x-module'; export * from './use-on-display'; +export * from './use-store'; diff --git a/packages/x-components/src/composables/use-store.ts b/packages/x-components/src/composables/use-store.ts new file mode 100644 index 0000000000..dfb7bcb67d --- /dev/null +++ b/packages/x-components/src/composables/use-store.ts @@ -0,0 +1,13 @@ +import { getCurrentInstance } from 'vue'; +import { Store } from 'vuex'; + +/** + * Function which returns the `$store` object from the current component instance. + * + * @returns The `$store` object from the current component instance. + * + * @public + */ +export function useStore(): Store { + return (getCurrentInstance()?.proxy as { $store: Store }).$store; +}