-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a comment to explain useEnhancedEffect
- Loading branch information
Showing
1 changed file
with
7 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
packages/mui-utils/src/useEnhancedEffect/useEnhancedEffect.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |