mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
RN: Prefer Destructured Import for createContext (#51400)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51400 Prefers using this as a destructured import instead of as a member expression of `React`. Changelog: [Internal] Reviewed By: javache Differential Revision: D74888314 fbshipit-source-id: 9224c7c371471fe1fc42c8d42d4b37a4edadcacf
This commit is contained in:
committed by
Facebook GitHub Bot
parent
255c197baf
commit
d7d10a4f0d
@@ -9,10 +9,11 @@
|
||||
*/
|
||||
|
||||
import * as React from 'react';
|
||||
import {createContext} from 'react';
|
||||
|
||||
type Value = {horizontal: boolean} | null;
|
||||
|
||||
const ScrollViewContext: React.Context<Value> = React.createContext(null);
|
||||
const ScrollViewContext: React.Context<Value> = createContext(null);
|
||||
if (__DEV__) {
|
||||
ScrollViewContext.displayName = 'ScrollViewContext';
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
*/
|
||||
|
||||
import * as React from 'react';
|
||||
import {createContext} from 'react';
|
||||
|
||||
type ContextType = ?string;
|
||||
|
||||
const Context: React.Context<ContextType> =
|
||||
React.createContext<ContextType>(null);
|
||||
const Context: React.Context<ContextType> = createContext<ContextType>(null);
|
||||
|
||||
if (__DEV__) {
|
||||
Context.displayName = 'ImageAnalyticsTagContext';
|
||||
|
||||
+2
-2
@@ -9,11 +9,11 @@
|
||||
*/
|
||||
|
||||
import * as React from 'react';
|
||||
import {createContext} from 'react';
|
||||
|
||||
export opaque type RootTag = number;
|
||||
|
||||
export const RootTagContext: React.Context<RootTag> =
|
||||
React.createContext<RootTag>(0);
|
||||
export const RootTagContext: React.Context<RootTag> = createContext<RootTag>(0);
|
||||
|
||||
if (__DEV__) {
|
||||
RootTagContext.displayName = 'RootTagContext';
|
||||
|
||||
+3
-2
@@ -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 <Text> element.
|
||||
*/
|
||||
const TextAncestorContext: React.Context<boolean> = React.createContext(false);
|
||||
const TextAncestorContext: React.Context<boolean> = createContext(false);
|
||||
if (__DEV__) {
|
||||
TextAncestorContext.displayName = 'TextAncestorContext';
|
||||
}
|
||||
|
||||
@@ -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<IPerformanceLogger> =
|
||||
React.createContext(GlobalPerformanceLogger);
|
||||
createContext(GlobalPerformanceLogger);
|
||||
if (__DEV__) {
|
||||
PerformanceLoggerContext.displayName = 'PerformanceLoggerContext';
|
||||
}
|
||||
|
||||
@@ -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<boolean>;
|
||||
"declare const TextAncestorContext: React.Context<boolean>;
|
||||
declare export default typeof TextAncestorContext;
|
||||
"
|
||||
`;
|
||||
|
||||
@@ -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<RNTesterTheme> =
|
||||
React.createContext(
|
||||
Appearance.getColorScheme() === 'dark' ? themes.dark : themes.light,
|
||||
);
|
||||
export const RNTesterThemeContext: React.Context<RNTesterTheme> = createContext(
|
||||
Appearance.getColorScheme() === 'dark' ? themes.dark : themes.light,
|
||||
);
|
||||
|
||||
@@ -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<?Context> =
|
||||
React.createContext(null);
|
||||
createContext(null);
|
||||
if (__DEV__) {
|
||||
VirtualizedListContext.displayName = 'VirtualizedListContext';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user