mirror of
https://github.com/grafana/grafana.git
synced 2025-09-26 02:03:57 +08:00

* influxdb: switch the raw influxql editor from angular to react * influxdb: raw-influxql: better callback-naming * influxdb: raw-influxql: use custom hook * influxdb: flux: raw-editor: add unit tests
18 lines
465 B
TypeScript
18 lines
465 B
TypeScript
import { useRef } from 'react';
|
|
import { uniqueId } from 'lodash';
|
|
|
|
export function useUniqueId(): string {
|
|
// we need to lazy-init this ref.
|
|
// otherwise we would call `uniqueId`
|
|
// on every render. unfortunately
|
|
// useRef does not have lazy-init builtin,
|
|
// like useState does. we do it manually.
|
|
const idRefLazy = useRef<string | null>(null);
|
|
|
|
if (idRefLazy.current == null) {
|
|
idRefLazy.current = uniqueId();
|
|
}
|
|
|
|
return idRefLazy.current;
|
|
}
|