Skip to content

Commit

Permalink
fix: replace useLayoutEffect into useIsomorphicLayoutEffect for serve…
Browse files Browse the repository at this point in the history
…r side rendering
  • Loading branch information
khsily authored and fkhadra committed Jan 16, 2024
1 parent 5759b3f commit 3c18d0b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/components/ToastContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import cx from 'clsx';
import React, { useLayoutEffect, useRef, useState } from 'react';
import React, { useRef, useState } from 'react';

import { toast } from '../core';
import { useToastContainer } from '../hooks/useToastContainer';
import { useIsomorphicLayoutEffect } from '../hooks/useIsomorphicLayoutEffect';
import { ToastContainerProps, ToastPosition } from '../types';
import { Default, Direction, isFn, parseClassName } from '../utils';
import { Toast } from './Toast';
Expand Down Expand Up @@ -56,7 +57,7 @@ export function ToastContainer(props: ToastContainerProps) {
}
}

useLayoutEffect(() => {
useIsomorphicLayoutEffect(() => {
if (stacked) {
const nodes = containerRef.current!.querySelectorAll('[data-in="true"]');
const gap = 12;
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/useIsomorphicLayoutEffect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { useEffect, useLayoutEffect } from 'react';

export const useIsomorphicLayoutEffect =
typeof window !== 'undefined' ? useLayoutEffect : useEffect;

0 comments on commit 3c18d0b

Please sign in to comment.