fre icon indicating copy to clipboard operation
fre copied to clipboard

Support for new React 18 hook - useSyncExternalStore

Open cliffordfajardo opened this issue 3 years ago • 2 comments
trafficstars

I just wanted to put this as a place holder item for now

  • https://github.com/reactwg/react-18/discussions/86

Some libraries that are using useSyncExternalStore already:

  • react-query: https://github.com/tannerlinsley/react-query/pull/3064/files

cliffordfajardo avatar Dec 07 '21 17:12 cliffordfajardo

Hi @cliffordfajardo, Here we need to explain in detail:

API level compatibility is not difficult, and the shim is also applicable to fre.

https://github.com/yisar/fre/blob/master/demo/src/use-sync-external-store.tsx

In addition to API compatibility, useSyncExternalStore internal implementation mainly solves the tearing problem, which is a defect of Concurrent mode.

React uses this API to degrade the internal scheduling to micro tasks, which loses the concurrency ability, but ensures the consistency of rendering.

Fre has the same defect. It may be useful to implement this API, but I don't think many libraries will use it in the short term.

yisar avatar Dec 08 '21 09:12 yisar

Came here because I wanted to use Xstate with a react alternative library. So that could be a use case. The @xstate/react package uses useSyncExternalStore

herrKlein avatar Jun 28 '22 06:06 herrKlein