mirror of
https://github.com/SteamDeckHomebrew/decky-frontend-lib.git
synced 2026-05-20 01:50:08 +02:00
feat(hooks): Added useParams hook (#36)
This commit is contained in:
1
src/deck-hooks/index.ts
Normal file
1
src/deck-hooks/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './useParams'
|
||||
15
src/deck-hooks/useParams.ts
Normal file
15
src/deck-hooks/useParams.ts
Normal 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
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user