Skip to content

Commit 365cee7

Browse files
committed
Initial shim of useSyncExternalStore
This sets up an initial shim implementation of useSyncExternalStore, via the use-sync-external-store package. It's designed to mimic the behavior of the built-in API, but is backwards compatible to any version of React that supports hooks. I have not yet implemented the built-in API, but once it exists, the use-sync-external-store package will always prefer that one. Library authors can depend on the shim and trust that their users get the correct implementation. See reactwg/react-18#86 for background on the API. The tests I've added here are designed to run against both the shim and built-in implementation, using our variant test flag feature. Tests that only apply to concurrent roots will live in a separate suite.
1 parent 46a0f05 commit 365cee7

File tree

7 files changed

+932
-7
lines changed

7 files changed

+932
-7
lines changed

packages/use-sync-external-store/src/__tests__/useSyncExternalStore-test.js packages/use-sync-external-store/extra.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @emails react-core
7+
* @flow
88
*/
99

1010
'use strict';
1111

12-
describe('useSyncExternalStore', () => {
13-
test('TODO', () => {});
14-
});
12+
export * from './src/useSyncExternalStoreExtra';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
if (process.env.NODE_ENV === 'production') {
4+
module.exports = require('./cjs/use-sync-external-store-extra.production.min.js');
5+
} else {
6+
module.exports = require('./cjs/use-sync-external-store-extra.development.js');
7+
}

packages/use-sync-external-store/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"README.md",
1313
"build-info.json",
1414
"index.js",
15+
"extra.js",
1516
"cjs/"
1617
],
1718
"license": "MIT",

0 commit comments

Comments
 (0)