Skip to content

Commit

Permalink
[core] Add a comment to explain useEnhancedEffect (mui#39035)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot authored and christophermorin committed Sep 21, 2023
1 parent 40a5aa1 commit 2e5faca
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/mui-utils/src/useEnhancedEffect/useEnhancedEffect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
'use client';
import * as React from 'react';

/**
* A version of `React.useLayoutEffect` that does not show a warning when server-side rendering.
* This is useful for effects that are only needed for client-side rendering but not for SSR.
*
* Before you use this hook, make sure to read https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85
* and confirm it doesn't apply to your use-case.
*/
const useEnhancedEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;

export default useEnhancedEffect;

0 comments on commit 2e5faca

Please sign in to comment.