refactor(FE-114): use React's useId hook for generating unique checkbox IDs in CheckboxInput

This commit is contained in:
rstubryan
2025-10-21 11:54:57 +07:00
parent 1ee1cf9ea9
commit 25a97e34c7
+4 -3
View File
@@ -1,6 +1,6 @@
'use client';
import { ChangeEventHandler, FocusEventHandler, ReactNode } from 'react';
import { ChangeEventHandler, FocusEventHandler, ReactNode, useId } from 'react';
import { cn } from '@/lib/helper';
import FieldMessage from '@/components/helper/FieldMessage';
@@ -101,8 +101,9 @@ const CheckboxInput = ({
error: 'checkbox-error',
};
// Generate unique ID for accessibility
const checkboxId = `checkbox-${name}-${Math.random().toString(36).substr(2, 9)}`;
// Generate unique ID for accessibility using React's useId hook for SSR compatibility
const generatedId = useId();
const checkboxId = `checkbox-${name}-${generatedId}`;
// Naked mode - only checkbox, no wrapper structure
if (naked) {