-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2362 from Agenta-AI/AGE-1464/implement-useIsomorp…
…hicLayoutEffect-to-prevent-using-useLayoutEffect-on-server (frontend)[AGE-1464]: implement useIsomorphicLayoutEffect hook to prevent using useLayoutEffect on server
- Loading branch information
Showing
2 changed files
with
11 additions
and
2 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {useLayoutEffect, useEffect} from "react" | ||
|
||
// useIsomorphicLayoutEffect is a custom hook that uses useLayoutEffect on the client-side | ||
// (when window is defined) and useEffect on the server-side (when window is undefined). | ||
// This ensures that the code runs correctly in both client-side and server-side environments. | ||
const useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect | ||
|
||
export default useIsomorphicLayoutEffect |
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