Skip to content

Commit

Permalink
fix(number_format_base): prevent warnings in SRR when using useLayout…
Browse files Browse the repository at this point in the history
…Effect.
  • Loading branch information
NicolasMontone authored and s-yadav committed May 20, 2023
1 parent 49a0003 commit bc47b78
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/number_format_base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ export default function NumberFormatBase<BaseType = InputAttributes>(
? geInputCaretPosition(focusedElm.current)
: undefined;

useLayoutEffect(() => {
// needed to prevent warning with useLayoutEffect on server
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect

useIsomorphicLayoutEffect(() => {
const input = focusedElm.current;
if (formattedValue !== lastUpdatedValue.current.formattedValue && input) {
const caretPos = getNewCaretPosition(
Expand Down

0 comments on commit bc47b78

Please sign in to comment.