Skip to content

Commit 14f6860

Browse files
committed
Update component.tsx
1 parent 62ce89b commit 14f6860

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

custom-component-library/components/ColorPicker/component.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ export const ColorPickerComponent: React.FC<CustomNodeProps<ColorPickerProps>> =
6868
const [hsvValue, setHsvValue] = React.useState(colord(text).toHsv())
6969

7070
const lastValidColor = useRef(text)
71+
const isUpdatingFromPicker = useRef(false)
7172

7273
// Debounced setValue to avoid excessive updates while dragging the picker
7374
const debouncedSetValue = useDebouncedCallback((value: string) => {
75+
isUpdatingFromPicker.current = true
7476
setValue(value)
7577
}, 150)
7678

@@ -97,6 +99,12 @@ export const ColorPickerComponent: React.FC<CustomNodeProps<ColorPickerProps>> =
9799
value={text}
98100
setValue={
99101
((value: string) => {
102+
// Prevent infinite loop when update is coming from color picker
103+
if (isUpdatingFromPicker.current) {
104+
isUpdatingFromPicker.current = false // Reset immediately
105+
return
106+
}
107+
100108
// Only update the color picker display if the input text is a
101109
// valid color
102110
const parsed = colord(value)

0 commit comments

Comments
 (0)