Skip to content

Commit

Permalink
Initial shim of useSyncExternalStore (#22211)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
acdlite committed Sep 2, 2021
1 parent 3385b37 commit 1314299
Show file tree
Hide file tree
Showing 7 changed files with 845 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
* 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
* @flow
*/

'use strict';

describe('useSyncExternalStore', () => {
test('TODO', () => {});
});
export * from './src/useSyncExternalStoreExtra';
7 changes: 7 additions & 0 deletions packages/use-sync-external-store/npm/extra.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-extra.production.min.js');
} else {
module.exports = require('./cjs/use-sync-external-store-extra.development.js');
}
1 change: 1 addition & 0 deletions packages/use-sync-external-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"README.md",
"build-info.json",
"index.js",
"extra.js",
"cjs/"
],
"license": "MIT",
Expand Down
Loading

0 comments on commit 1314299

Please sign in to comment.