diff --git a/src/nav/AppNavigator.js b/src/nav/AppNavigator.js index d95354eeccc..d768b89583f 100644 --- a/src/nav/AppNavigator.js +++ b/src/nav/AppNavigator.js @@ -42,7 +42,7 @@ import EmojiPickerScreen from '../emoji/EmojiPickerScreen'; import LegalScreen from '../settings/LegalScreen'; import UserStatusScreen from '../user-status/UserStatusScreen'; import SharingScreen from '../sharing/SharingScreen'; -import withHaveServerDataGate from '../withHaveServerDataGate'; +import { useHaveServerDataGate } from '../withHaveServerDataGate'; export type AppNavigatorParamList = {| 'account-pick': RouteParamsOf, @@ -108,40 +108,40 @@ export default function AppNavigator(props: Props) { {/* These screens expect server data in order to function normally. */} - - - - + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - + + + + + + {/* These screens do not expect server data in order to function normally. */} diff --git a/src/withHaveServerDataGate.js b/src/withHaveServerDataGate.js index 48733f27d76..48e033e0f82 100644 --- a/src/withHaveServerDataGate.js +++ b/src/withHaveServerDataGate.js @@ -1,5 +1,5 @@ /* @flow strict-local */ -import React, { type ComponentType, type ElementConfig } from 'react'; +import React, { type ComponentType, type ElementConfig, useRef } from 'react'; import { connect } from './react-redux'; import type { Dispatch } from './types'; @@ -16,6 +16,9 @@ import FullScreenLoading from './common/FullScreenLoading'; * The implementation uses props named `dispatch` and `haveServerData`; the * inner component shouldn't try to accept props with those names, and the * caller shouldn't try to pass them in. + * + * Inside a render method, don't call this directly: like most HOCs, it will + * return a new value each time. Instead, use `useHaveServerDataGate`. */ // It sure seems like Flow should catch the `dispatch` / `haveServerData` // thing and reflect it in the types; it's not clear why it doesn't. @@ -61,3 +64,18 @@ export default function withHaveServerDataGate>>( + Comp: C, +): ComponentType<$Exact>> { + // Not `useMemo`, because that function's memoization is only a + // performance optimization and not a semantic guarantee. + return useRef(withHaveServerDataGate(Comp)).current; +}