Skip to content

Commit

Permalink
Set up use-sync-external-store package (facebook#22202)
Browse files Browse the repository at this point in the history
This package will be a shim for the built-in useSyncExternalStore API
(not yet implemented).
  • Loading branch information
acdlite authored and zhengjitf committed Apr 15, 2022
1 parent e94db9d commit c582dea
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions ReactVersions.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const experimentalPackages = [
'react-fs',
'react-pg',
'react-server-dom-webpack',
'use-sync-external-store',
];

module.exports = {
Expand Down
5 changes: 5 additions & 0 deletions packages/use-sync-external-store/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# use-sync-external-store

Backwards compatible shim for React's `useSyncExternalStore`. Works with any React that supports hooks.

Until `useSyncExternalStore` is documented, refer to https://github.com/reactwg/react-18/discussions/86
12 changes: 12 additions & 0 deletions packages/use-sync-external-store/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

'use strict';

export * from './src/useSyncExternalStore';
7 changes: 7 additions & 0 deletions packages/use-sync-external-store/npm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/use-sync-external-store.production.min.js');
} else {
module.exports = require('./cjs/use-sync-external-store.development.js');
}
21 changes: 21 additions & 0 deletions packages/use-sync-external-store/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "use-sync-external-store",
"description": "Backwards compatible shim for React's useSyncExternalStore. Works with any React that supports hooks.",
"version": "0.0.1",
"repository": {
"type": "git",
"url": "https://github.com/facebook/react.git",
"directory": "packages/use-sync-external-store"
},
"files": [
"LICENSE",
"README.md",
"build-info.json",
"index.js",
"cjs/"
],
"license": "MIT",
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
*/

'use strict';

describe('useSyncExternalStore', () => {
test('TODO', () => {});
});
12 changes: 12 additions & 0 deletions packages/use-sync-external-store/src/useSyncExternalStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

export function useSyncExternalStore() {
throw new Error('Not yet implemented');
}
9 changes: 9 additions & 0 deletions scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,15 @@ const bundles = [
externals: ['react'],
},

/******* Shim for useSyncExternalState *******/
{
bundleTypes: [NODE_DEV, NODE_PROD],
moduleType: ISOMORPHIC,
entry: 'use-sync-external-store',
global: 'useSyncExternalStore',
externals: ['react'],
},

/******* React Scheduler (experimental) *******/
{
bundleTypes: [
Expand Down

0 comments on commit c582dea

Please sign in to comment.