You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/react/hooks/useParamState.ts

21 lines
498 B

import { useCurrentStateAndParams, useRouter } from '@uirouter/react';
export function useParamState<T>(
param: string,
parseParam: (param: string | undefined) => T | undefined = (param) =>
param as unknown as T
) {
const {
params: { [param]: paramValue },
} = useCurrentStateAndParams();
const router = useRouter();
const state = parseParam(paramValue);
return [
state,
(value?: T) => {
router.stateService.go('.', { [param]: value });
},
] as const;
}