Skip to content

Commit 8ffed73

Browse files
committed
add use sync external store shim
this will use a shim for older versions of React and use the one from React.useSyncExternalStore in >v18
1 parent 92dd7c0 commit 8ffed73

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

packages/react/package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@
4141
"@preact/signals-core": "workspace:^1.2.1"
4242
},
4343
"peerDependencies": {
44-
"react": "17.x || 18.x"
44+
"react": "17.x || 18.x",
45+
"use-sync-external-store": "^1.2.0"
4546
},
4647
"devDependencies": {
48+
"@types/react": "^18.0.18",
49+
"@types/react-dom": "^18.0.6",
50+
"@types/use-sync-external-store": "^0.0.3",
4751
"react": "^18.2.0",
4852
"react-dom": "^18.2.0",
49-
"@types/react": "^18.0.18",
50-
"@types/react-dom": "^18.0.6"
53+
"use-sync-external-store": "^1.2.0"
5154
}
5255
}

packages/react/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as internals,
88
} from "react";
99
import React from "react";
10+
import {useSyncExternalStore} from "use-sync-external-store/shim"
1011
import {
1112
signal,
1213
computed,
@@ -75,7 +76,7 @@ function setCurrentUpdater(updater?: Effect) {
7576
*
7677
* [1]
7778
* @see https://reactjs.org/docs/hooks-reference.html#usesyncexternalstore
78-
* @see https://github.com/reactwg/react-18/discussions/86
79+
* @see https://github.com/reactjs/rfcs/blob/main/text/0214-use-sync-external-store.md
7980
*/
8081
function createEffectStore() {
8182
let updater!: Effect;
@@ -140,7 +141,7 @@ Object.defineProperty(internals.ReactCurrentDispatcher, "current", {
140141

141142
const store = api.useMemo(createEffectStore, Empty);
142143

143-
api.useSyncExternalStore(
144+
useSyncExternalStore(
144145
store.subscribe,
145146
store.getSnapshot,
146147
store.getSnapshot

pnpm-lock.yaml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)