Skip to content

Commit 93b50be

Browse files
rickhanloniifacebook-github-bot
authored andcommitted
Replace use-subscripton with use-sync-external-store (#33770)
Summary: Pull Request resolved: #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
1 parent e5469c4 commit 93b50be

File tree

5 files changed

+19
-27
lines changed

5 files changed

+19
-27
lines changed

BUCK

+1-1
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ rn_library(
759759
"//xplat/js:node_modules__react_19shallow_19renderer",
760760
"//xplat/js:node_modules__regenerator_19runtime",
761761
"//xplat/js:node_modules__stacktrace_19parser",
762-
"//xplat/js:node_modules__use_19subscription",
762+
"//xplat/js:node_modules__use_19sync_19external_19store",
763763
"//xplat/js:node_modules__whatwg_19fetch",
764764
"//xplat/js/RKJSModules/Libraries/Polyfills:Polyfills",
765765
"//xplat/js/RKJSModules/Libraries/React:React",

Libraries/Utilities/useColorScheme.js

+9-15
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,18 @@
88
* @flow strict-local
99
*/
1010

11-
import {useMemo} from 'react';
12-
import {useSubscription} from 'use-subscription';
11+
'use strict';
12+
13+
import {useSyncExternalStore} from 'use-sync-external-store/shim';
1314
import Appearance from './Appearance';
1415
import type {ColorSchemeName} from './NativeAppearance';
1516

1617
export default function useColorScheme(): ?ColorSchemeName {
17-
const subscription = useMemo(
18-
() => ({
19-
getCurrentValue: () => Appearance.getColorScheme(),
20-
subscribe: callback => {
21-
const appearanceSubscription = Appearance.addChangeListener(callback);
22-
return () => {
23-
appearanceSubscription.remove();
24-
};
25-
},
26-
}),
27-
[],
18+
return useSyncExternalStore(
19+
callback => {
20+
const appearanceSubscription = Appearance.addChangeListener(callback);
21+
return () => appearanceSubscription.remove();
22+
},
23+
() => Appearance.getColorScheme(),
2824
);
29-
30-
return useSubscription(subscription);
3125
}

flow/use-subscription.js flow/use-sync-external-store.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
'use strict';
1313

14-
declare module 'use-subscription' {
15-
declare export function useSubscription<Value>(subscription: {|
16-
getCurrentValue: () => Value,
14+
declare module 'use-sync-external-store/shim' {
15+
declare export function useSyncExternalStore<Value>(
1716
subscribe: (callback: Function) => () => void,
18-
|}): Value;
17+
getCurrentValue: () => Value,
18+
): Value;
1919
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
"regenerator-runtime": "^0.13.2",
126126
"scheduler": "^0.21.0",
127127
"stacktrace-parser": "^0.1.3",
128-
"use-subscription": ">=1.0.0 <1.6.0",
128+
"use-sync-external-store": "^1.0.0",
129129
"whatwg-fetch": "^3.0.0",
130130
"ws": "^6.1.4"
131131
},

yarn.lock

+4-6
Original file line numberDiff line numberDiff line change
@@ -7239,12 +7239,10 @@ urix@^0.1.0:
72397239
resolved "https://registry.yarnpkg.com/urix/-/urix-0.1.0.tgz#da937f7a62e21fec1fd18d49b35c2935067a6c72"
72407240
integrity sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI=
72417241

7242-
"use-subscription@>=1.0.0 <1.6.0":
7243-
version "1.5.1"
7244-
resolved "https://registry.yarnpkg.com/use-subscription/-/use-subscription-1.5.1.tgz#73501107f02fad84c6dd57965beb0b75c68c42d1"
7245-
integrity sha512-Xv2a1P/yReAjAbhylMfFplFKj9GssgTwN7RlcTxBujFQcloStWNDQdc4g4NRWH9xS4i/FDk04vQBptAXoF3VcA==
7246-
dependencies:
7247-
object-assign "^4.1.1"
7242+
use-sync-external-store@^1.0.0:
7243+
version "1.0.0"
7244+
resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.0.0.tgz#d98f4a9c2e73d0f958e7e2d2c2bfb5f618cbd8fd"
7245+
integrity sha512-AFVsxg5GkFg8GDcxnl+Z0lMAz9rE8DGJCc28qnBuQF7lac57B5smLcT37aXpXIIPz75rW4g3eXHPjhHwdGskOw==
72487246

72497247
use@^3.1.0:
72507248
version "3.1.1"

0 commit comments

Comments
 (0)