diff --git a/packages/grafana-ui/src/components/Switch/Switch.tsx b/packages/grafana-ui/src/components/Switch/Switch.tsx index 31a01a0ee28..5ea11edbdac 100644 --- a/packages/grafana-ui/src/components/Switch/Switch.tsx +++ b/packages/grafana-ui/src/components/Switch/Switch.tsx @@ -1,4 +1,4 @@ -import React, { HTMLProps } from 'react'; +import React, { HTMLProps, useRef } from 'react'; import { css, cx } from 'emotion'; import uniqueId from 'lodash/uniqueId'; import { GrafanaTheme } from '@grafana/data'; @@ -79,7 +79,7 @@ export const Switch = React.forwardRef( ({ value, checked, disabled = false, onChange, ...inputProps }, ref) => { const theme = useTheme(); const styles = getSwitchStyles(theme); - const switchId = uniqueId('switch-'); + const switchIdRef = useRef(uniqueId('switch-')); return (
@@ -90,11 +90,11 @@ export const Switch = React.forwardRef( onChange={event => { onChange?.(event); }} - id={switchId} + id={switchIdRef.current} {...inputProps} ref={ref} /> -
); }