keycloak_theme/src/tools/useConst.ts
2023-03-16 22:43:09 +01:00

11 lines
255 B
TypeScript

import { useState } from "react";
/**
* Compute a value on first render and never again,
* Equivalent of const [x] = useState(()=> ...)
*/
export function useConst<T>(getValue: () => T): T {
const [value] = useState(getValue);
return value;
}