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