useSyncExternalStore
It lets you subscribe to an external store. It returns the snapshot of the data in the store.
const snapshot = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot?);- The
subscribefunction should subscribe to the store and return a function that unsubscribes. - The
getSnapshotfunction should read a snapshot of the data from the store.
Important
When possible, we recommend using built-in React state with
useStateanduseReducerinstead. TheuseSyncExternalStoreAPI is mostly useful if you need to integrate with existing non-React code.
These following hooks are great for the perceived performance (mostly).