1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 21:39:40 +02:00
portainer/app/react/hooks/useIdParam.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

14 lines
335 B
TypeScript
Raw Permalink Normal View History

import { useCurrentStateAndParams } from '@uirouter/react';
export function useIdParam(param = 'id'): number {
const { params } = useCurrentStateAndParams();
const stringId = params[param];
const id = parseInt(stringId, 10);
if (!id || Number.isNaN(id)) {
throw new Error('id url param is required');
}
return id;
}