diff --git a/packages/react-native/Libraries/Components/ScrollView/ScrollViewContext.js b/packages/react-native/Libraries/Components/ScrollView/ScrollViewContext.js index e08fda8bc65..3756e83f3d4 100644 --- a/packages/react-native/Libraries/Components/ScrollView/ScrollViewContext.js +++ b/packages/react-native/Libraries/Components/ScrollView/ScrollViewContext.js @@ -9,10 +9,11 @@ */ import * as React from 'react'; +import {createContext} from 'react'; type Value = {horizontal: boolean} | null; -const ScrollViewContext: React.Context = React.createContext(null); +const ScrollViewContext: React.Context = createContext(null); if (__DEV__) { ScrollViewContext.displayName = 'ScrollViewContext'; } diff --git a/packages/react-native/Libraries/Image/ImageAnalyticsTagContext.js b/packages/react-native/Libraries/Image/ImageAnalyticsTagContext.js index 81ecba24da5..9cc314b962e 100644 --- a/packages/react-native/Libraries/Image/ImageAnalyticsTagContext.js +++ b/packages/react-native/Libraries/Image/ImageAnalyticsTagContext.js @@ -9,11 +9,11 @@ */ import * as React from 'react'; +import {createContext} from 'react'; type ContextType = ?string; -const Context: React.Context = - React.createContext(null); +const Context: React.Context = createContext(null); if (__DEV__) { Context.displayName = 'ImageAnalyticsTagContext'; diff --git a/packages/react-native/Libraries/ReactNative/RootTag.js b/packages/react-native/Libraries/ReactNative/RootTag.js index c1b655d21c9..843489917fa 100644 --- a/packages/react-native/Libraries/ReactNative/RootTag.js +++ b/packages/react-native/Libraries/ReactNative/RootTag.js @@ -9,11 +9,11 @@ */ import * as React from 'react'; +import {createContext} from 'react'; export opaque type RootTag = number; -export const RootTagContext: React.Context = - React.createContext(0); +export const RootTagContext: React.Context = createContext(0); if (__DEV__) { RootTagContext.displayName = 'RootTagContext'; diff --git a/packages/react-native/Libraries/Text/TextAncestor.js b/packages/react-native/Libraries/Text/TextAncestor.js index 105ee7d4883..c1fd4216c35 100644 --- a/packages/react-native/Libraries/Text/TextAncestor.js +++ b/packages/react-native/Libraries/Text/TextAncestor.js @@ -10,12 +10,13 @@ 'use strict'; -const React = require('react'); +import * as React from 'react'; +import {createContext} from 'react'; /** * Whether the current element is the descendant of a element. */ -const TextAncestorContext: React.Context = React.createContext(false); +const TextAncestorContext: React.Context = createContext(false); if (__DEV__) { TextAncestorContext.displayName = 'TextAncestorContext'; } diff --git a/packages/react-native/Libraries/Utilities/PerformanceLoggerContext.js b/packages/react-native/Libraries/Utilities/PerformanceLoggerContext.js index cb17ae33076..f0baf48ff3e 100644 --- a/packages/react-native/Libraries/Utilities/PerformanceLoggerContext.js +++ b/packages/react-native/Libraries/Utilities/PerformanceLoggerContext.js @@ -12,7 +12,7 @@ import type {IPerformanceLogger} from './createPerformanceLogger'; import GlobalPerformanceLogger from './GlobalPerformanceLogger'; import * as React from 'react'; -import {useContext} from 'react'; +import {createContext, useContext} from 'react'; /** * This is a React Context that provides a scoped instance of IPerformanceLogger. @@ -21,7 +21,7 @@ import {useContext} from 'react'; * See React docs about using Context: https://react.dev/docs/context.html */ const PerformanceLoggerContext: React.Context = - React.createContext(GlobalPerformanceLogger); + createContext(GlobalPerformanceLogger); if (__DEV__) { PerformanceLoggerContext.displayName = 'PerformanceLoggerContext'; } diff --git a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap index 4b1035b4ce6..9e0ff4f8979 100644 --- a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap +++ b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap @@ -7831,8 +7831,7 @@ declare export default typeof TextImpl; `; exports[`public API should not change unintentionally Libraries/Text/TextAncestor.js 1`] = ` -"declare const React: $FlowFixMe; -declare const TextAncestorContext: React.Context; +"declare const TextAncestorContext: React.Context; declare export default typeof TextAncestorContext; " `; diff --git a/packages/rn-tester/js/components/RNTesterTheme.js b/packages/rn-tester/js/components/RNTesterTheme.js index 8cc4cf6f0a7..62894cab233 100644 --- a/packages/rn-tester/js/components/RNTesterTheme.js +++ b/packages/rn-tester/js/components/RNTesterTheme.js @@ -11,6 +11,7 @@ import type {ColorValue, ImageSource} from 'react-native'; import * as React from 'react'; +import {createContext} from 'react'; import {Appearance} from 'react-native'; export type RNTesterTheme = { @@ -137,7 +138,6 @@ export const RNTesterDarkTheme = { }; export const themes = {light: RNTesterLightTheme, dark: RNTesterDarkTheme}; -export const RNTesterThemeContext: React.Context = - React.createContext( - Appearance.getColorScheme() === 'dark' ? themes.dark : themes.light, - ); +export const RNTesterThemeContext: React.Context = createContext( + Appearance.getColorScheme() === 'dark' ? themes.dark : themes.light, +); diff --git a/packages/virtualized-lists/Lists/VirtualizedListContext.js b/packages/virtualized-lists/Lists/VirtualizedListContext.js index b40128f2dd2..9897ecd7e95 100644 --- a/packages/virtualized-lists/Lists/VirtualizedListContext.js +++ b/packages/virtualized-lists/Lists/VirtualizedListContext.js @@ -11,7 +11,7 @@ import typeof VirtualizedList from './VirtualizedList'; import * as React from 'react'; -import {useContext, useMemo} from 'react'; +import {createContext, useContext, useMemo} from 'react'; type Context = $ReadOnly<{ cellKey: ?string, @@ -35,7 +35,7 @@ type Context = $ReadOnly<{ }>; export const VirtualizedListContext: React.Context = - React.createContext(null); + createContext(null); if (__DEV__) { VirtualizedListContext.displayName = 'VirtualizedListContext'; }