feat(hooks): Added useParams hook (#36)

This commit is contained in:
OMGDuke
2022-10-05 19:42:54 -06:00
committed by GitHub
parent 67a76e2691
commit e2920dd91e
3 changed files with 17 additions and 0 deletions

1
src/deck-hooks/index.ts Normal file
View File

@@ -0,0 +1 @@
export * from './useParams'

View File

@@ -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>() => T

View File

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