Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up use-sync-external-store package #22202

Merged
merged 1 commit into from
Aug 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:/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:/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', () => {});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw you can use test.todo() here, this is a use case we built it for 👍

});
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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this be a default export?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idk I just did it this way because that's how useSubscription does it. Can decide later.

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