Skip to content

Commit

Permalink
fix: 修复useRef缓存引起的color实例内部属性未更新,导致的在Form中reset引起的死循环
Browse files Browse the repository at this point in the history
  • Loading branch information
huangchen1031 committed Sep 27, 2024
1 parent d6933f1 commit cdb480d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/color-picker/components/panel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ const Panel = forwardRef<HTMLDivElement, ColorPickerProps>((props, ref) => {
});

const colorInstanceRef = useRef<Color>(new Color(innerValue || defaultEmptyColor));
useEffect(() => {
colorInstanceRef.current = new Color(innerValue || defaultEmptyColor);
return () => {
colorInstanceRef.current = null;
};
}, [innerValue, defaultEmptyColor]);

const getModeByColor = colorInstanceRef.current.isGradient ? 'linear-gradient' : 'monochrome';
const formatRef = useRef<TdColorPickerProps['format']>(colorInstanceRef.current.isGradient ? 'CSS' : format ?? 'RGB');

Expand Down

0 comments on commit cdb480d

Please sign in to comment.