Set up use-sync-external-store package (#22202)
This package will be a shim for the built-in useSyncExternalStore API (not yet implemented).
Andrew Clark committed
Aug 28, 2021 at 16:57 UTC
46a0f050aacd8b2159b8db99b599a4b69e682189
8 files changed
+81
ReactVersions.js
+1
@@ -47,6 +47,7 @@ const experimentalPackages = [
47
'react-fs',
48
'react-pg',
49
'react-server-dom-webpack',
50
+ 'use-sync-external-store',
51
];
52
53
module.exports = {
packages/use-sync-external-store/README.md
new
+5
@@ -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
packages/use-sync-external-store/index.js
new
+12
@@ -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';
packages/use-sync-external-store/npm/index.js
new
+7
@@ -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
+}
packages/use-sync-external-store/package.json
new
+21
@@ -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
+}
packages/use-sync-external-store/src/__tests__/useSyncExternalStore-test.js
new
+14
@@ -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
+});
packages/use-sync-external-store/src/useSyncExternalStore.js
new
+12
@@ -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
@@ -684,6 +684,15 @@ const bundles = [
684
externals: ['react'],
685
},
686
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
+
696
/******* React Scheduler (experimental) *******/
697
{
698
bundleTypes: [