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';