-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Use `useSyncExternalStore` in hooks - Remove `useId` - Remove `useNativeLazyLoading` BREAKING CHANGE
- Loading branch information
1 parent
41fc8eb
commit 46f8fe5
Showing
41 changed files
with
113 additions
and
1,008 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
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
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
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
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
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,9 +1,7 @@ | ||
import { renderHook } from '@testing-library/react-hooks' | ||
import useClientHydrated from './useClientHydrated' | ||
|
||
it('should update hydrated state after first render', () => { | ||
let hookOutput = renderHook(() => useClientHydrated()) | ||
expect(hookOutput.result.current).toBe(false) | ||
hookOutput = renderHook(() => useClientHydrated()) | ||
it('should be hydrated on client', () => { | ||
const hookOutput = renderHook(() => useClientHydrated()) | ||
expect(hookOutput.result.current).toBe(true) | ||
}) |
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,17 +1,21 @@ | ||
import { useEffect } from 'react' | ||
let clientHydrated = false | ||
import { useSyncExternalStore } from 'react' | ||
|
||
// Void subscription function. You can't go back after hydrating. | ||
const subscribe = () => { | ||
return () => {} | ||
}; | ||
|
||
const getSnapshot = () => true | ||
|
||
const getServerSnapshot = () => false; | ||
|
||
/** | ||
* Returns false when serverside rendering and during the first render pass (hydration) in the client. | ||
* Use this to modify behavior of components when they can be certain they are running client side. | ||
* Like check a media query during the initial render. | ||
* */ | ||
function useClientHydrated() { | ||
useEffect(() => { | ||
if (!clientHydrated) clientHydrated = true | ||
}, []) | ||
|
||
return clientHydrated | ||
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) | ||
} | ||
|
||
export default useClientHydrated |
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.