Skip to content

Commit 46a0f05

Browse files
authored
Set up use-sync-external-store package (#22202)
This package will be a shim for the built-in useSyncExternalStore API (not yet implemented).
1 parent 8723e77 commit 46a0f05

File tree

8 files changed

+81
-0
lines changed

8 files changed

+81
-0
lines changed

ReactVersions.js

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const experimentalPackages = [
4747
'react-fs',
4848
'react-pg',
4949
'react-server-dom-webpack',
50+
'use-sync-external-store',
5051
];
5152

5253
module.exports = {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# use-sync-external-store
2+
3+
Backwards compatible shim for React's `useSyncExternalStore`. Works with any React that supports hooks.
4+
5+
Until `useSyncExternalStore` is documented, refer to https://github.com/reactwg/react-18/discussions/86
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
'use strict';
11+
12+
export * from './src/useSyncExternalStore';
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.production.min.js');
5+
} else {
6+
module.exports = require('./cjs/use-sync-external-store.development.js');
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "use-sync-external-store",
3+
"description": "Backwards compatible shim for React's useSyncExternalStore. Works with any React that supports hooks.",
4+
"version": "0.0.1",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/facebook/react.git",
8+
"directory": "packages/use-sync-external-store"
9+
},
10+
"files": [
11+
"LICENSE",
12+
"README.md",
13+
"build-info.json",
14+
"index.js",
15+
"cjs/"
16+
],
17+
"license": "MIT",
18+
"peerDependencies": {
19+
"react": "^16.8.0 || ^17.0.0"
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @emails react-core
8+
*/
9+
10+
'use strict';
11+
12+
describe('useSyncExternalStore', () => {
13+
test('TODO', () => {});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
export function useSyncExternalStore() {
11+
throw new Error('Not yet implemented');
12+
}

scripts/rollup/bundles.js

+9
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,15 @@ const bundles = [
684684
externals: ['react'],
685685
},
686686

687+
/******* Shim for useSyncExternalState *******/
688+
{
689+
bundleTypes: [NODE_DEV, NODE_PROD],
690+
moduleType: ISOMORPHIC,
691+
entry: 'use-sync-external-store',
692+
global: 'useSyncExternalStore',
693+
externals: ['react'],
694+
},
695+
687696
/******* React Scheduler (experimental) *******/
688697
{
689698
bundleTypes: [

0 commit comments

Comments
 (0)