react/packages/use-sync-external-store
Andrew Clark 79b8fc6670
Implement getServerSnapshot in userspace shim (#22359)
* Convert useSES shim tests to use React DOM

Idea is that eventually we'll run these tests against an actual build of
React DOM 17 to test backwards compatibility.

* Implement getServerSnapshot in userspace shim

If the DOM is not present, we assume that we are running in a server
environment and return the result of `getServerSnapshot`.

This heuristic doesn't work in React Native, so we'll need to provide
a separate native build (using the `.native` extension). I've left this
for a follow-up.

We can't call `getServerSnapshot` on the client, because in versions of
React before 18, there's no built-in mechanism to detect whether we're
hydrating. To avoid a server mismatch warning, users must account for
this themselves and return the correct value inside `getSnapshot`.

Note that none of this is relevant to the built-in API that is being
added in 18. This only affects the userspace shim that is provided
for backwards compatibility with versions 16 and 17.
2021-09-20 08:32:13 -07:00
..
npm Initial shim of useSyncExternalStore (#22211) 2021-09-01 17:52:38 -07:00
src Implement getServerSnapshot in userspace shim (#22359) 2021-09-20 08:32:13 -07:00
README.md Set up use-sync-external-store package (#22202) 2021-08-28 13:57:47 -07:00
extra.js Initial shim of useSyncExternalStore (#22211) 2021-09-01 17:52:38 -07:00
index.js Set up use-sync-external-store package (#22202) 2021-08-28 13:57:47 -07:00
package.json Initial shim of useSyncExternalStore (#22211) 2021-09-01 17:52:38 -07:00

README.md

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