Fix flow types (#18204)
* Added missing @flow pragma to React.js * Fixed useContext() return type definition * Fixed previously masked Flow errors in DevTools and react-interactions packages * Added displayName to internal Context Flow type * Removed Flow generic annotations for createResponder This seems to cause a parsing error. (Not sure why.) The API is deprecated anyway so I'm being lazy for now and just adding a .
Brian Vaughn committed
Mar 3, 2020 at 12:46 UTC
d2158d6ccbcbd998d1cd1c06ac6c6682cbeafd04
29 files changed
+150
-95
packages/react-devtools-shared/src/devtools/ContextMenu/ContextMenu.js
+47
-35
@@ -14,6 +14,8 @@ import {RegistryContext} from './Contexts';
14
15
import styles from './ContextMenu.css';
16
17
+import type {RegistryContextType} from './Contexts';
18
+
19
function respositionToFit(element: HTMLElement, pageX: number, pageY: number) {
20
const ownerWindow = element.ownerDocument.defaultView;
21
if (element !== null) {
@@ -52,7 +54,7 @@ type Props = {|
54
|};
55
56
export default function ContextMenu({children, id}: Props) {
55
- const {registerMenu} = useContext(RegistryContext);
57
+ const {registerMenu} = useContext<RegistryContextType>(RegistryContext);
58
59
const [state, setState] = useState(HIDDEN_STATE);
60
@@ -61,12 +63,15 @@ export default function ContextMenu({children, id}: Props) {
63
const menuRef = useRef(null);
64
65
useEffect(() => {
64
- const ownerDocument = bodyAccessorRef.current.ownerDocument;
65
- containerRef.current = ownerDocument.createElement('div');
66
- ownerDocument.body.appendChild(containerRef.current);
67
- return () => {
68
- ownerDocument.body.removeChild(containerRef.current);
69
- };
66
+ const element = bodyAccessorRef.current;
67
+ if (element !== null) {
68
+ const ownerDocument = element.ownerDocument;
69
+ containerRef.current = ownerDocument.createElement('div');
70
+ ownerDocument.body.appendChild(containerRef.current);
71
+ return () => {
72
+ ownerDocument.body.removeChild(containerRef.current);
73
+ };
74
+ }
75
}, []);
76
77
useEffect(() => {
@@ -82,45 +87,52 @@ export default function ContextMenu({children, id}: Props) {
87
return;
88
}
89
85
- const menu = menuRef.current;
90
+ const menu = ((menuRef.current: any): HTMLElement);
91
+ const container = containerRef.current;
92
+ if (container !== null) {
93
+ const hideUnlessContains = event => {
94
+ if (!menu.contains(event.target)) {
95
+ setState(HIDDEN_STATE);
96
+ }
97
+ };
98
87
- const hideUnlessContains = event => {
88
- if (!menu.contains(event.target)) {
99
+ const hide = event => {
100
setState(HIDDEN_STATE);
90
- }
91
- };
101
+ };
102
93
- const hide = event => {
94
- setState(HIDDEN_STATE);
95
- };
103
+ const ownerDocument = container.ownerDocument;
104
+ ownerDocument.addEventListener('mousedown', hideUnlessContains);
105
+ ownerDocument.addEventListener('touchstart', hideUnlessContains);
106
+ ownerDocument.addEventListener('keydown', hideUnlessContains);
107
97
- const ownerDocument = containerRef.current.ownerDocument;
98
- ownerDocument.addEventListener('mousedown', hideUnlessContains);
99
- ownerDocument.addEventListener('touchstart', hideUnlessContains);
100
- ownerDocument.addEventListener('keydown', hideUnlessContains);
108
+ const ownerWindow = ownerDocument.defaultView;
109
+ ownerWindow.addEventListener('resize', hide);
110
102
- const ownerWindow = ownerDocument.defaultView;
103
- ownerWindow.addEventListener('resize', hide);
111
+ respositionToFit(menu, state.pageX, state.pageY);
112
105
- respositionToFit(menu, state.pageX, state.pageY);
113
+ return () => {
114
+ ownerDocument.removeEventListener('mousedown', hideUnlessContains);
115
+ ownerDocument.removeEventListener('touchstart', hideUnlessContains);
116
+ ownerDocument.removeEventListener('keydown', hideUnlessContains);
117
107
- return () => {
108
- ownerDocument.removeEventListener('mousedown', hideUnlessContains);
109
- ownerDocument.removeEventListener('touchstart', hideUnlessContains);
110
- ownerDocument.removeEventListener('keydown', hideUnlessContains);
111
-
112
- ownerWindow.removeEventListener('resize', hide);
113
- };
118
+ ownerWindow.removeEventListener('resize', hide);
119
+ };
120
+ }
121
}, [state]);
122
123
if (!state.isVisible) {
124
return <div ref={bodyAccessorRef} />;
125
} else {
119
- return createPortal(
120
- <div ref={menuRef} className={styles.ContextMenu}>
121
- {children(state.data)}
122
- </div>,
123
- containerRef.current,
124
- );
126
+ const container = containerRef.current;
127
+ if (container !== null) {
128
+ return createPortal(
129
+ <div ref={menuRef} className={styles.ContextMenu}>
130
+ {children(state.data)}
131
+ </div>,
132
+ container,
133
+ );
134
+ } else {
135
+ return null;
136
+ }
137
}
138
}
packages/react-devtools-shared/src/devtools/ContextMenu/ContextMenuItem.js
+3
-1
@@ -13,6 +13,8 @@ import {RegistryContext} from './Contexts';
13
14
import styles from './ContextMenuItem.css';
15
16
+import type {RegistryContextType} from './Contexts';
17
+
18
type Props = {|
19
children: React$Node,
20
onClick: () => void,
@@ -20,7 +22,7 @@ type Props = {|
22
|};
23
24
export default function ContextMenuItem({children, onClick, title}: Props) {
23
- const {hideMenu} = useContext(RegistryContext);
25
+ const {hideMenu} = useContext<RegistryContextType>(RegistryContext);
26
27
const handleClick = event => {
28
onClick();
packages/react-devtools-shared/src/devtools/ContextMenu/Contexts.js
+12
-1
@@ -55,7 +55,18 @@ function registerMenu(id: string, showFn: ShowFn, hideFn: HideFn) {
55
};
56
}
57
58
-export const RegistryContext = createContext({
58
+export type RegistryContextType = {|
59
+ hideMenu: () => void,
60
+ showMenu: ({|
61
+ data: Object,
62
+ id: string,
63
+ pageX: number,
64
+ pageY: number,
65
+ |}) => void,
66
+ registerMenu: (string, ShowFn, HideFn) => Function,
67
+|};
68
+
69
+export const RegistryContext = createContext<RegistryContextType>({
70
hideMenu,
71
showMenu,
72
registerMenu,
packages/react-devtools-shared/src/devtools/ContextMenu/useContextMenu.js
+6
-5
@@ -10,6 +10,7 @@
10
import {useContext, useEffect} from 'react';
11
import {RegistryContext} from './Contexts';
12
13
+import type {RegistryContextType} from './Contexts';
14
import type {ElementRef} from 'react';
15
16
export default function useContextMenu({
@@ -21,7 +22,7 @@ export default function useContextMenu({
22
id: string,
23
ref: {current: ElementRef<'div'> | null},
24
|}) {
24
- const {showMenu} = useContext(RegistryContext);
25
+ const {showMenu} = useContext<RegistryContextType>(RegistryContext);
26
27
useEffect(() => {
28
if (ref.current !== null) {
@@ -30,11 +31,11 @@ export default function useContextMenu({
31
event.stopPropagation();
32
33
const pageX =
33
- event.pageX ||
34
- (event.touches && ((event: any): TouchEvent).touches[0].pageX);
34
+ (event: any).pageX ||
35
+ (event.touches && (event: any).touches[0].pageX);
36
const pageY =
36
- event.pageY ||
37
- (event.touches && ((event: any): TouchEvent).touches[0].pageY);
37
+ (event: any).pageY ||
38
+ (event.touches && (event: any).touches[0].pageY);
39
40
showMenu({data, id, pageX, pageY});
41
};
packages/react-devtools-shared/src/devtools/views/Components/Components.js
+22
-22
@@ -32,11 +32,30 @@ import {NativeStyleContextController} from './NativeStyleEditor/context';
32
33
import styles from './Components.css';
34
35
+type Orientation = 'horizontal' | 'vertical';
36
+
37
+type ResizeActionType =
38
+ | 'ACTION_SET_DID_MOUNT'
39
+ | 'ACTION_SET_IS_RESIZING'
40
+ | 'ACTION_SET_HORIZONTAL_PERCENTAGE'
41
+ | 'ACTION_SET_VERTICAL_PERCENTAGE';
42
+
43
+type ResizeAction = {|
44
+ type: ResizeActionType,
45
+ payload: any,
46
+|};
47
+
48
+type ResizeState = {|
49
+ horizontalPercentage: number,
50
+ isResizing: boolean,
51
+ verticalPercentage: number,
52
+|};
53
+
54
function Components(_: {||}) {
36
- const wrapperElementRef = useRef<HTMLElement>(null);
37
- const resizeElementRef = useRef<HTMLElement>(null);
55
+ const wrapperElementRef = useRef<null | HTMLElement>(null);
56
+ const resizeElementRef = useRef<null | HTMLElement>(null);
57
39
- const [state, dispatch] = useReducer<ResizeState, ResizeAction>(
58
+ const [state, dispatch] = useReducer<ResizeState, any, ResizeAction>(
59
resizeReducer,
60
null,
61
initResizeState,
@@ -171,25 +190,6 @@ const LOCAL_STORAGE_KEY = 'React::DevTools::createResizeReducer';
190
const VERTICAL_MODE_MAX_WIDTH = 600;
191
const MINIMUM_SIZE = 50;
192
174
-type Orientation = 'horizontal' | 'vertical';
175
-
176
-type ResizeActionType =
177
- | 'ACTION_SET_DID_MOUNT'
178
- | 'ACTION_SET_IS_RESIZING'
179
- | 'ACTION_SET_HORIZONTAL_PERCENTAGE'
180
- | 'ACTION_SET_VERTICAL_PERCENTAGE';
181
-
182
-type ResizeAction = {|
183
- type: ResizeActionType,
184
- payload: any,
185
-|};
186
-
187
-type ResizeState = {|
188
- horizontalPercentage: number,
189
- isResizing: boolean,
190
- verticalPercentage: number,
191
-|};
192
-
193
function initResizeState(): ResizeState {
194
let horizontalPercentage = 0.65;
195
let verticalPercentage = 0.5;
packages/react-devtools-shared/src/devtools/views/Components/EditableName.js
+1
-1
@@ -12,7 +12,7 @@ import {useCallback, useState} from 'react';
12
import AutoSizeInput from './NativeStyleEditor/AutoSizeInput';
13
import styles from './EditableName.css';
14
15
-type OverrideNameFn = (path: Array<string | number>, value: any) => void;
15
+type OverrideNameFn = (name: string, value: any) => void;
16
17
type EditableNameProps = {|
18
autoFocus?: boolean,
packages/react-devtools-shared/src/devtools/views/Components/HooksTree.js
+1
-1
@@ -241,7 +241,7 @@ function HookView({canEditHooks, hook, id, inspectPath, path}: HookViewProps) {
241
} else {
242
let overrideValueFn = null;
243
// TODO Maybe read editable value from debug hook?
244
- if (canEditHooks && isStateEditable) {
244
+ if (canEditHooks && isStateEditable && hookID !== null) {
245
overrideValueFn = (
246
absolutePath: Array<string | number>,
247
newValue: any,
packages/react-devtools-shared/src/devtools/views/Components/InspectedElementContext.js
+4
-2
@@ -51,14 +51,16 @@ export type GetInspectedElement = (
51
id: number,
52
) => InspectedElementFrontend | null;
53
54
-type Context = {|
54
+export type InspectedElementContextType = {|
55
copyInspectedElementPath: CopyInspectedElementPath,
56
getInspectedElementPath: GetInspectedElementPath,
57
getInspectedElement: GetInspectedElement,
58
storeAsGlobal: StoreAsGlobal,
59
|};
60
61
-const InspectedElementContext = createContext<Context>(((null: any): Context));
61
+const InspectedElementContext = createContext<InspectedElementContextType>(
62
+ ((null: any): InspectedElementContextType),
63
+);
64
InspectedElementContext.displayName = 'InspectedElementContext';
65
66
type ResolveFn = (inspectedElement: InspectedElementFrontend) => void;
packages/react-devtools-shared/src/devtools/views/Components/NativeStyleEditor/context.js
+6
-3
@@ -24,6 +24,9 @@ import {
24
} from 'react-devtools-shared/src/devtools/views/context';
25
import {TreeStateContext} from '../TreeContext';
26
27
+import type {StateContext} from '../TreeContext';
28
+import type {FrontendBridge} from 'react-devtools-shared/src/bridge';
29
+import type Store from 'react-devtools-shared/src/devtools/store';
30
import type {StyleAndLayout as StyleAndLayoutBackend} from 'react-devtools-shared/src/backend/NativeStyleEditor/types';
31
import type {StyleAndLayout as StyleAndLayoutFrontend} from './types';
32
import type {Element} from 'react-devtools-shared/src/devtools/views/Components/types';
@@ -77,8 +80,8 @@ type Props = {|
80
|};
81
82
function NativeStyleContextController({children}: Props) {
80
- const bridge = useContext(BridgeContext);
81
- const store = useContext(StoreContext);
83
+ const bridge = useContext<FrontendBridge>(BridgeContext);
84
+ const store = useContext<Store>(StoreContext);
85
86
const getStyleAndLayout = useCallback<GetStyleAndLayout>(
87
(id: number) => {
@@ -95,7 +98,7 @@ function NativeStyleContextController({children}: Props) {
98
// It's very important that this context consumes selectedElementID and not NativeStyleID.
99
// Otherwise the effect that sends the "inspect" message across the bridge-
100
// would itself be blocked by the same render that suspends (waiting for the data).
98
- const {selectedElementID} = useContext(TreeStateContext);
101
+ const {selectedElementID} = useContext<StateContext>(TreeStateContext);
102
103
const [
104
currentStyleAndLayout,
packages/react-devtools-shared/src/devtools/views/Components/OwnersStack.js
+1
-1
@@ -77,7 +77,7 @@ export default function OwnerStack() {
77
const {ownerID} = useContext(TreeStateContext);
78
const treeDispatch = useContext(TreeDispatcherContext);
79
80
- const [state, dispatch] = useReducer<State, Action>(dialogReducer, {
80
+ const [state, dispatch] = useReducer<State, State, Action>(dialogReducer, {
81
ownerID: null,
82
owners: [],
83
selectedIndex: 0,
packages/react-devtools-shared/src/devtools/views/Components/SelectedElement.js
+4
-5
@@ -37,9 +37,11 @@ import {
37
38
import styles from './SelectedElement.css';
39
40
+import type {ContextMenuContextType} from '../context';
41
import type {
42
CopyInspectedElementPath,
43
GetInspectedElementPath,
44
+ InspectedElementContextType,
45
StoreAsGlobal,
46
} from './InspectedElementContext';
47
import type {Element, InspectedElement} from './types';
@@ -62,8 +64,7 @@ export default function SelectedElement(_: Props) {
64
getInspectedElementPath,
65
getInspectedElement,
66
storeAsGlobal,
65
- viewInspectedElementPath,
66
- } = useContext(InspectedElementContext);
67
+ } = useContext<InspectedElementContextType>(InspectedElementContext);
68
69
const element =
70
inspectedElementID !== null
@@ -244,7 +245,6 @@ export default function SelectedElement(_: Props) {
245
getInspectedElementPath={getInspectedElementPath}
246
inspectedElement={inspectedElement}
247
storeAsGlobal={storeAsGlobal}
247
- viewInspectedElementPath={viewInspectedElementPath}
248
/>
249
)}
250
</div>
@@ -270,7 +270,6 @@ function InspectedElementView({
270
getInspectedElementPath,
271
inspectedElement,
272
storeAsGlobal,
273
- viewInspectedElementPath,
273
}: InspectedElementViewProps) {
274
const {id, type} = element;
275
const {
@@ -293,7 +292,7 @@ function InspectedElementView({
292
const {
293
isEnabledForInspectedElement,
294
viewAttributeSourceFunction,
296
- } = useContext(ContextMenuContext);
295
+ } = useContext<ContextMenuContextType>(ContextMenuContext);
296
297
const inspectContextPath = useCallback(
298
(path: Array<string | number>) => {
packages/react-devtools-shared/src/devtools/views/ModalDialog.js
+1
-1
@@ -78,7 +78,7 @@ type Props = {|
78
|};
79
80
function ModalDialogContextController({children}: Props) {
81
- const [state, dispatch] = useReducer<State, Action>(dialogReducer, {
81
+ const [state, dispatch] = useReducer<State, State, Action>(dialogReducer, {
82
canBeDismissed: true,
83
content: null,
84
isVisible: false,
packages/react-devtools-shared/src/devtools/views/Profiler/CommitFlamegraph.js
+3
-1
@@ -96,7 +96,9 @@ type Props = {|
96
|};
97
98
function CommitFlamegraph({chartData, commitTree, height, width}: Props) {
99
- const [hoveredFiberData, hoverFiber] = useState<number | null>(null);
99
+ const [hoveredFiberData, hoverFiber] = useState<TooltipFiberData | null>(
100
+ null,
101
+ );
102
const {lineHeight} = useContext(SettingsContext);
103
const {selectFiber, selectedFiberID} = useContext(ProfilerContext);
104
packages/react-devtools-shared/src/devtools/views/Profiler/CommitRanked.js
+3
-1
@@ -94,7 +94,9 @@ type Props = {|
94
|};
95
96
function CommitRanked({chartData, commitTree, height, width}: Props) {
97
- const [hoveredFiberData, hoverFiber] = useState<number | null>(null);
97
+ const [hoveredFiberData, hoverFiber] = useState<TooltipFiberData | null>(
98
+ null,
99
+ );
100
const {lineHeight} = useContext(SettingsContext);
101
const {selectedFiberID, selectFiber} = useContext(ProfilerContext);
102
packages/react-devtools-shared/src/devtools/views/Profiler/ProfilerContext.js
+4
-1
@@ -124,7 +124,10 @@ function ProfilerContextController({children}: Props) {
124
supportsProfiling,
125
} = useSubscription<StoreProfilingState>(subscription);
126
127
- const [prevProfilingData, setPrevProfilingData] = useState();
127
+ const [
128
+ prevProfilingData,
129
+ setPrevProfilingData,
130
+ ] = useState<ProfilingDataFrontend | null>(null);
131
const [rootID, setRootID] = useState<number | null>(null);
132
133
if (prevProfilingData !== profilingData) {
packages/react-devtools-shared/src/devtools/views/Profiler/ProfilingImportExportButtons.js
+4
-2
@@ -39,7 +39,9 @@ export default function ProfilingImportExportButtons() {
39
return;
40
}
41
42
- if (profilingData !== null && downloadRef.current !== null) {
42
+ const anchorElement = downloadRef.current;
43
+
44
+ if (profilingData !== null && anchorElement !== null) {
45
const profilingDataExport = prepareProfilingDataExport(profilingData);
46
const date = new Date();
47
const dateString = date
@@ -55,7 +57,7 @@ export default function ProfilingImportExportButtons() {
57
})
58
.replace(/:/g, '-');
59
downloadFile(
58
- downloadRef.current,
60
+ anchorElement,
61
`profiling-data.${dateString}.${timeString}.json`,
62
JSON.stringify(profilingDataExport, null, 2),
63
);
packages/react-devtools-shared/src/devtools/views/context.js
+1
-1
@@ -23,7 +23,7 @@ StoreContext.displayName = 'StoreContext';
23
24
export type ContextMenuContextType = {|
25
isEnabledForInspectedElement: boolean,
26
- viewAttributeSourceFunction?: ?ViewAttributeSource,
26
+ viewAttributeSourceFunction: ViewAttributeSource | null,
27
|};
28
29
export const ContextMenuContext = createContext<ContextMenuContextType>({
packages/react-devtools-shared/src/devtools/views/hooks.js
+2
-1
@@ -78,6 +78,7 @@ export function useEditableValue(
78
externalValue: any,
79
): [UseEditableValueState, UseEditableValueDispatch] {
80
const [state, dispatch] = useReducer<
81
+ UseEditableValueState,
82
UseEditableValueState,
83
UseEditableValueAction,
84
>(useEditableValueReducer, {
@@ -158,7 +159,7 @@ export function useLocalStorage<T>(
159
}
160
}, [initialValue, key]);
161
161
- const [storedValue, setStoredValue] = useState(getValueFromLocalStorage);
162
+ const [storedValue, setStoredValue] = useState<any>(getValueFromLocalStorage);
163
164
const setValue = useCallback(
165
value => {
packages/react-devtools-shell/src/app/SuspenseTree/index.js
+1
-1
@@ -128,7 +128,7 @@ function SuspenseListTest() {
128
}
129
130
function LoadLater() {
131
- const [loadChild, setLoadChild] = useState(0);
131
+ const [loadChild, setLoadChild] = useState(false);
132
return (
133
<Suspense
134
fallback={
packages/react-interactions/events/src/dom/ContextMenu.js
+2
-1
@@ -113,6 +113,7 @@ const contextMenuImpl = {
113
},
114
};
115
116
+// $FlowFixMe Can't add generic types without causing a parsing/syntax errors
117
export const ContextMenuResponder = React.DEPRECATED_createResponder(
118
'ContextMenu',
119
contextMenuImpl,
@@ -120,6 +121,6 @@ export const ContextMenuResponder = React.DEPRECATED_createResponder(
121
122
export function useContextMenu(
123
props: ContextMenuProps,
123
-): ReactEventResponderListener<any, any> {
124
+): ?ReactEventResponderListener<any, any> {
125
return React.DEPRECATED_useResponder(ContextMenuResponder, props);
126
}
packages/react-interactions/events/src/dom/Focus.js
+4
-2
@@ -494,6 +494,7 @@ const focusResponderImpl = {
494
},
495
};
496
497
+// $FlowFixMe Can't add generic types without causing a parsing/syntax errors
498
export const FocusResponder = React.DEPRECATED_createResponder(
499
'Focus',
500
focusResponderImpl,
@@ -501,7 +502,7 @@ export const FocusResponder = React.DEPRECATED_createResponder(
502
503
export function useFocus(
504
props: FocusProps,
504
-): ReactEventResponderListener<any, any> {
505
+): ?ReactEventResponderListener<any, any> {
506
return React.DEPRECATED_useResponder(FocusResponder, props);
507
}
508
@@ -680,6 +681,7 @@ const focusWithinResponderImpl = {
681
},
682
};
683
684
+// $FlowFixMe Can't add generic types without causing a parsing/syntax errors
685
export const FocusWithinResponder = React.DEPRECATED_createResponder(
686
'FocusWithin',
687
focusWithinResponderImpl,
@@ -687,6 +689,6 @@ export const FocusWithinResponder = React.DEPRECATED_createResponder(
689
690
export function useFocusWithin(
691
props: FocusWithinProps,
690
-): ReactEventResponderListener<any, any> {
692
+): ?ReactEventResponderListener<any, any> {
693
return React.DEPRECATED_useResponder(FocusWithinResponder, props);
694
}
packages/react-interactions/events/src/dom/Hover.js
+2
-1
@@ -378,6 +378,7 @@ const hoverResponderFallbackImpl = {
378
onUnmount: unmountResponder,
379
};
380
381
+// $FlowFixMe Can't add generic types without causing a parsing/syntax errors
382
export const HoverResponder = React.DEPRECATED_createResponder(
383
'Hover',
384
hasPointerEvents ? hoverResponderImpl : hoverResponderFallbackImpl,
@@ -385,6 +386,6 @@ export const HoverResponder = React.DEPRECATED_createResponder(
386
387
export function useHover(
388
props: HoverProps,
388
-): ReactEventResponderListener<any, any> {
389
+): ?ReactEventResponderListener<any, any> {
390
return React.DEPRECATED_useResponder(HoverResponder, props);
391
}
packages/react-interactions/events/src/dom/Input.js
+2
-1
@@ -212,6 +212,7 @@ const inputResponderImpl = {
212
},
213
};
214
215
+// $FlowFixMe Can't add generic types without causing a parsing/syntax errors
216
export const InputResponder = React.DEPRECATED_createResponder(
217
'Input',
218
inputResponderImpl,
@@ -219,6 +220,6 @@ export const InputResponder = React.DEPRECATED_createResponder(
220
221
export function useInput(
222
props: InputResponderProps,
222
-): ReactEventResponderListener<any, any> {
223
+): ?ReactEventResponderListener<any, any> {
224
return React.DEPRECATED_useResponder(InputResponder, props);
225
}
packages/react-interactions/events/src/dom/Keyboard.js
+2
-1
@@ -229,6 +229,7 @@ const keyboardResponderImpl = {
229
},
230
};
231
232
+// $FlowFixMe Can't add generic types without causing a parsing/syntax errors
233
export const KeyboardResponder = React.DEPRECATED_createResponder(
234
'Keyboard',
235
keyboardResponderImpl,
@@ -236,6 +237,6 @@ export const KeyboardResponder = React.DEPRECATED_createResponder(
237
238
export function useKeyboard(
239
props: KeyboardProps,
239
-): ReactEventResponderListener<any, any> {
240
+): ?ReactEventResponderListener<any, any> {
241
return React.DEPRECATED_useResponder(KeyboardResponder, props);
242
}
packages/react-interactions/events/src/dom/PressLegacy.js
+2
-1
@@ -903,6 +903,7 @@ const pressResponderImpl = {
903
},
904
};
905
906
+// $FlowFixMe Can't add generic types without causing a parsing/syntax errors
907
export const PressResponder = React.DEPRECATED_createResponder(
908
'Press',
909
pressResponderImpl,
@@ -910,6 +911,6 @@ export const PressResponder = React.DEPRECATED_createResponder(
911
912
export function usePress(
913
props: PressProps,
913
-): ReactEventResponderListener<any, any> {
914
+): ?ReactEventResponderListener<any, any> {
915
return React.DEPRECATED_useResponder(PressResponder, props);
916
}
packages/react-interactions/events/src/dom/Tap.js
+4
-1
@@ -721,11 +721,14 @@ const responderImpl = {
721
},
722
};
723
724
+// $FlowFixMe Can't add generic types without causing a parsing/syntax errors
725
export const TapResponder = React.DEPRECATED_createResponder(
726
'Tap',
727
responderImpl,
728
);
729
729
-export function useTap(props: TapProps): ReactEventResponderListener<any, any> {
730
+export function useTap(
731
+ props: TapProps,
732
+): ?ReactEventResponderListener<any, any> {
733
return React.DEPRECATED_useResponder(TapResponder, props);
734
}
packages/react/src/React.js
+2
@@ -3,6 +3,8 @@
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 ReactVersion from 'shared/ReactVersion';
packages/react/src/ReactHooks.js
+1
-1
@@ -37,7 +37,7 @@ function resolveDispatcher() {
37
export function useContext<T>(
38
Context: ReactContext<T>,
39
unstable_observedBits: number | boolean | void,
40
-) {
40
+): T {
41
const dispatcher = resolveDispatcher();
42
if (__DEV__) {
43
if (unstable_observedBits !== undefined) {
packages/shared/ReactTypes.js
+3
@@ -66,6 +66,9 @@ export type ReactContext<T> = {
66
// DEV only
67
_currentRenderer?: Object | null,
68
_currentRenderer2?: Object | null,
69
+ // This value may be added by application code
70
+ // to improve DEV tooling display names
71
+ displayName?: string,
72
...
73
};
74