Skip to content

Commit

Permalink
fix: only call useLayoutEffect client-side (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissantamaria committed Mar 29, 2022
1 parent 938e45f commit 31db1bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/hooks/useDebugDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/

import { useLayoutEffect, useRef } from 'react';
import { useRef } from 'react';

import { IS_DEBUG_MODE } from '../utils/variables';
import DebugDashboard from '../libs/DebugDashboard';
import useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect';

const useDebugDashboard = ({
node
}) => {
const debugDashboard = useRef();

useLayoutEffect(() => {
useIsomorphicLayoutEffect(() => {
if (IS_DEBUG_MODE) {
debugDashboard.current = new DebugDashboard(node);
}
Expand Down
5 changes: 5 additions & 0 deletions src/hooks/useIsomorphicLayoutEffect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { useLayoutEffect, useEffect } from 'react';

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

export default useIsomorphicLayoutEffect;

0 comments on commit 31db1bf

Please sign in to comment.