From 481c59a2d22f64b9cf0f1935e62d73ef6b5fdb0d Mon Sep 17 00:00:00 2001 From: Laura Martinez Garcia Date: Wed, 31 Jan 2024 10:29:19 +0100 Subject: [PATCH] feat: create useStore composable EMP-3452 --- 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; +}