From e2920dd91e81d915a2319280d8473df71a4e4232 Mon Sep 17 00:00:00 2001 From: OMGDuke Date: Wed, 5 Oct 2022 19:42:54 -0600 Subject: [PATCH] feat(hooks): Added useParams hook (#36) --- src/deck-hooks/index.ts | 1 + src/deck-hooks/useParams.ts | 15 +++++++++++++++ src/index.ts | 1 + 3 files changed, 17 insertions(+) create mode 100644 src/deck-hooks/index.ts create mode 100644 src/deck-hooks/useParams.ts diff --git a/src/deck-hooks/index.ts b/src/deck-hooks/index.ts new file mode 100644 index 0000000..1009bae --- /dev/null +++ b/src/deck-hooks/index.ts @@ -0,0 +1 @@ +export * from './useParams' diff --git a/src/deck-hooks/useParams.ts b/src/deck-hooks/useParams.ts new file mode 100644 index 0000000..39f7fe3 --- /dev/null +++ b/src/deck-hooks/useParams.ts @@ -0,0 +1,15 @@ +import { ReactRouter } from "../webpack"; + +/** + * Get the current params from ReactRouter + * + * @returns an object with the current ReactRouter params + * + * @example + * import { useParams } from "decky-frontend-lib"; + * + * const { appid } = useParams<{ appid: string }>() + */ +export const useParams = Object.values(ReactRouter).find((val) => + /return (\w)\?\1\.params:{}/.test(`${val}`) +) as () => T \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 3ab76d5..0d36125 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,7 @@ export * from './custom-components'; export * from './custom-hooks'; export * from './deck-components'; +export * from './deck-hooks' export * from './plugin'; export * from './webpack'; export * from './utils';