Skip to content

Commit

Permalink
Remove imperative handle
Browse files Browse the repository at this point in the history
  • Loading branch information
michellocana committed May 7, 2024
1 parent f0cd6c4 commit bffcd95
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/auto-text-size-react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export function AutoTextSize({

useEffect(() => updateTextSizeRef.current?.(), [children]);

useImperativeHandle(onUpdateRef, () => onUpdate)
useEffect(() => {
onUpdateRef.current = onUpdate;
}, [onUpdate]);

const refCallback = useCallback(
(innerEl: HTMLElement | null) => {
Expand All @@ -51,7 +53,7 @@ export function AutoTextSize({
maxFontSizePx,
fontSizePrecisionPx,
// Not passing the callback ref directly so we can always get the latest value
onUpdate: () => onUpdateRef.current(),
onUpdate: () => onUpdateRef.current?.(),
});
},
[mode, minFontSizePx, maxFontSizePx, fontSizePrecisionPx]
Expand Down

0 comments on commit bffcd95

Please sign in to comment.