-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* use native `useSyncExternalStore` hook from React 18 * use native `useId` hook from React 18 * update changelog
- Loading branch information
1 parent
8652f80
commit ed98bad
Showing
6 changed files
with
4 additions
and
239 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,2 @@ | ||
import React from 'react' | ||
import { env } from '../utils/env' | ||
import { useIsoMorphicEffect } from './use-iso-morphic-effect' | ||
import { useServerHandoffComplete } from './use-server-handoff-complete' | ||
|
||
// We used a "simple" approach first which worked for SSR and rehydration on the client. However we | ||
// didn't take care of the Suspense case. To fix this we used the approach the @reach-ui/auto-id | ||
// uses. | ||
// | ||
// Credits: https://github.com/reach/reach-ui/blob/develop/packages/auto-id/src/index.tsx | ||
|
||
export let useId = | ||
// Prefer React's `useId` if it's available. | ||
React.useId ?? | ||
function useId() { | ||
let ready = useServerHandoffComplete() | ||
let [id, setId] = React.useState(ready ? () => env.nextId() : null) | ||
|
||
useIsoMorphicEffect(() => { | ||
if (id === null) setId(env.nextId()) | ||
}, [id]) | ||
|
||
return id != null ? '' + id : undefined | ||
} | ||
// Re-exporting the useId hook such that we can easily mock this hook in tests. | ||
export { useId } from 'react' |
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
38 changes: 0 additions & 38 deletions
38
packages/@headlessui-react/src/use-sync-external-store-shim/index.ts
This file was deleted.
Oops, something went wrong.
154 changes: 0 additions & 154 deletions
154
...ages/@headlessui-react/src/use-sync-external-store-shim/useSyncExternalStoreShimClient.ts
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
...ages/@headlessui-react/src/use-sync-external-store-shim/useSyncExternalStoreShimServer.ts
This file was deleted.
Oops, something went wrong.