mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
93b50be8c2
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/33770 React has replaced use-subscription with the React 18 compatible use-sync-external-store. Changelog: [General][Changed] - Replace use-subscripton with use-sync-external-store Reviewed By: ryancat Differential Revision: D35592432 fbshipit-source-id: cc2016f66940e53f3614e110bafb02240bae1ae4
26 lines
699 B
JavaScript
26 lines
699 B
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow strict-local
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
import {useSyncExternalStore} from 'use-sync-external-store/shim';
|
|
import Appearance from './Appearance';
|
|
import type {ColorSchemeName} from './NativeAppearance';
|
|
|
|
export default function useColorScheme(): ?ColorSchemeName {
|
|
return useSyncExternalStore(
|
|
callback => {
|
|
const appearanceSubscription = Appearance.addChangeListener(callback);
|
|
return () => appearanceSubscription.remove();
|
|
},
|
|
() => Appearance.getColorScheme(),
|
|
);
|
|
}
|