main
js 21 lines 728 Bytes
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow
8 */
9
10 import {useSyncExternalStore as client} from './useSyncExternalStoreShimClient';
11 import {useSyncExternalStore as server} from './useSyncExternalStoreShimServer';
12 import {isServerEnvironment} from './isServerEnvironment';
13 import {useSyncExternalStore as builtInAPI} from 'react';
14
15 const shim = isServerEnvironment ? server : client;
16
17 export const useSyncExternalStore: <T>(
18 subscribe: (() => void) => () => void,
19 getSnapshot: () => T,
20 getServerSnapshot?: () => T,
21 ) => T = builtInAPI !== undefined ? builtInAPI : shim;