diff --git a/lib/components/integrity-handler.react.js b/lib/components/integrity-handler.react.js --- a/lib/components/integrity-handler.react.js +++ b/lib/components/integrity-handler.react.js @@ -1,11 +1,10 @@ // @flow import * as React from 'react'; -import { useDispatch } from 'react-redux'; import { updateIntegrityStoreActionType } from '../actions/integrity-actions.js'; import { splitIntoChunks } from '../utils/array.js'; -import { useSelector } from '../utils/redux-utils.js'; +import { useSelector, useDispatch } from '../utils/redux-utils.js'; const BATCH_SIZE = 50; // Time between hashing of each thread batch diff --git a/lib/components/thread-draft-updater.react.js b/lib/components/thread-draft-updater.react.js --- a/lib/components/thread-draft-updater.react.js +++ b/lib/components/thread-draft-updater.react.js @@ -2,13 +2,12 @@ import invariant from 'invariant'; import * as React from 'react'; -import { useDispatch } from 'react-redux'; import { moveDraftActionType } from '../actions/draft-actions.js'; import { pendingToRealizedThreadIDsSelector } from '../selectors/thread-selectors.js'; import { draftKeyFromThreadID } from '../shared/thread-utils.js'; import type { AppState } from '../types/redux-types.js'; -import { useSelector } from '../utils/redux-utils.js'; +import { useSelector, useDispatch } from '../utils/redux-utils.js'; const ThreadDraftUpdater: React.ComponentType<{}> = React.memo<{}>( function ThreadDraftUpdater() { diff --git a/lib/hooks/disconnected-bar.js b/lib/hooks/disconnected-bar.js --- a/lib/hooks/disconnected-bar.js +++ b/lib/hooks/disconnected-bar.js @@ -2,14 +2,13 @@ import invariant from 'invariant'; import * as React from 'react'; -import { useDispatch } from 'react-redux'; import { connectionSelector } from '../selectors/keyserver-selectors.js'; import { updateDisconnectedBarActionType, type ConnectionStatus, } from '../types/socket-types.js'; -import { useSelector } from '../utils/redux-utils.js'; +import { useSelector, useDispatch } from '../utils/redux-utils.js'; function useDisconnectedBarVisibilityHandler(networkConnected: boolean): void { const dispatch = useDispatch(); diff --git a/lib/hooks/relationship-prompt.js b/lib/hooks/relationship-prompt.js --- a/lib/hooks/relationship-prompt.js +++ b/lib/hooks/relationship-prompt.js @@ -2,7 +2,6 @@ import invariant from 'invariant'; import * as React from 'react'; -import { useSelector } from 'react-redux'; import { updateRelationships as serverUpdateRelationships, @@ -19,6 +18,7 @@ useDispatchActionPromise, useServerCall, } from '../utils/action-utils.js'; +import { useSelector } from '../utils/redux-utils.js'; type RelationshipCallbacks = { +blockUser: () => void, diff --git a/lib/hooks/theme.js b/lib/hooks/theme.js --- a/lib/hooks/theme.js +++ b/lib/hooks/theme.js @@ -1,7 +1,6 @@ // @flow import * as React from 'react'; -import { useDispatch } from 'react-redux'; import { updateThemeInfoActionType } from '../actions/theme-actions.js'; import type { Shape } from '../types/core.js'; @@ -10,7 +9,7 @@ GlobalThemeInfo, GlobalThemePreference, } from '../types/theme-types.js'; -import { useSelector } from '../utils/redux-utils.js'; +import { useSelector, useDispatch } from '../utils/redux-utils.js'; function useUpdateSystemTheme(): (colorScheme: ?GlobalTheme) => mixed { const globalThemeInfo = useSelector(state => state.globalThemeInfo); diff --git a/lib/selectors/chat-selectors.js b/lib/selectors/chat-selectors.js --- a/lib/selectors/chat-selectors.js +++ b/lib/selectors/chat-selectors.js @@ -6,7 +6,6 @@ import _map from 'lodash/fp/map.js'; import _orderBy from 'lodash/fp/orderBy.js'; import * as React from 'react'; -import { useSelector } from 'react-redux'; import { createSelector } from 'reselect'; import { createObjectSelector } from 'reselect-map'; @@ -53,6 +52,7 @@ import { threeDays } from '../utils/date-utils.js'; import type { EntityText } from '../utils/entity-text.js'; import memoize2 from '../utils/memoize.js'; +import { useSelector } from '../utils/redux-utils.js'; export type SidebarItem = | { diff --git a/lib/shared/lifecycle-utils.js b/lib/shared/lifecycle-utils.js --- a/lib/shared/lifecycle-utils.js +++ b/lib/shared/lifecycle-utils.js @@ -1,6 +1,6 @@ // @flow -import { useSelector } from 'react-redux'; +import { useSelector } from '../utils/redux-utils.js'; // Note: This hook mimics the prior state.foreground property // and considers `inactive` on iOS as equivalent to `active` diff --git a/lib/shared/search-utils.js b/lib/shared/search-utils.js --- a/lib/shared/search-utils.js +++ b/lib/shared/search-utils.js @@ -1,7 +1,6 @@ // @flow import * as React from 'react'; -import { useSelector } from 'react-redux'; import SearchIndex from './search-index.js'; import { @@ -38,6 +37,7 @@ useDispatchActionPromise, } from '../utils/action-utils.js'; import { values } from '../utils/objects.js'; +import { useSelector } from '../utils/redux-utils.js'; const notFriendNotice = 'not friend'; diff --git a/lib/socket/activity-handler.react.js b/lib/socket/activity-handler.react.js --- a/lib/socket/activity-handler.react.js +++ b/lib/socket/activity-handler.react.js @@ -2,7 +2,6 @@ import invariant from 'invariant'; import * as React from 'react'; -import { useDispatch } from 'react-redux'; import { updateActivityActionTypes, @@ -14,7 +13,7 @@ import { queueActivityUpdatesActionType } from '../types/activity-types.js'; import type { ConnectionStatus } from '../types/socket-types.js'; import { useDispatchActionPromise } from '../utils/action-utils.js'; -import { useSelector } from '../utils/redux-utils.js'; +import { useSelector, useDispatch } from '../utils/redux-utils.js'; type Props = { +activeThread: ?string, diff --git a/lib/socket/message-handler.react.js b/lib/socket/message-handler.react.js --- a/lib/socket/message-handler.react.js +++ b/lib/socket/message-handler.react.js @@ -1,7 +1,6 @@ // @flow import * as React from 'react'; -import { useDispatch } from 'react-redux'; import { processMessagesActionType } from '../actions/message-actions.js'; import { @@ -9,6 +8,7 @@ serverSocketMessageTypes, type SocketListener, } from '../types/socket-types.js'; +import { useDispatch } from '../utils/redux-utils.js'; type Props = { +addListener: (listener: SocketListener) => void, diff --git a/lib/socket/request-response-handler.react.js b/lib/socket/request-response-handler.react.js --- a/lib/socket/request-response-handler.react.js +++ b/lib/socket/request-response-handler.react.js @@ -2,7 +2,6 @@ import invariant from 'invariant'; import * as React from 'react'; -import { useDispatch } from 'react-redux'; import { InflightRequests } from './inflight-requests.js'; import { connectionSelector } from '../selectors/keyserver-selectors.js'; @@ -23,7 +22,7 @@ type ConnectionInfo, } from '../types/socket-types.js'; import { ServerError, SocketTimeout } from '../utils/errors.js'; -import { useSelector } from '../utils/redux-utils.js'; +import { useSelector, useDispatch } from '../utils/redux-utils.js'; type BaseProps = { +inflightRequests: ?InflightRequests, diff --git a/lib/socket/update-handler.react.js b/lib/socket/update-handler.react.js --- a/lib/socket/update-handler.react.js +++ b/lib/socket/update-handler.react.js @@ -3,7 +3,6 @@ import invariant from 'invariant'; import * as React from 'react'; import { useEffect } from 'react'; -import { useDispatch } from 'react-redux'; import { connectionSelector } from '../selectors/keyserver-selectors.js'; import { @@ -14,7 +13,7 @@ clientSocketMessageTypes, } from '../types/socket-types.js'; import { processUpdatesActionType } from '../types/update-types.js'; -import { useSelector } from '../utils/redux-utils.js'; +import { useSelector, useDispatch } from '../utils/redux-utils.js'; type Props = { +sendMessage: (message: ClientSocketMessageWithoutID) => number, diff --git a/lib/utils/action-utils.js b/lib/utils/action-utils.js --- a/lib/utils/action-utils.js +++ b/lib/utils/action-utils.js @@ -3,7 +3,6 @@ import invariant from 'invariant'; import _memoize from 'lodash/memoize.js'; import * as React from 'react'; -import { useSelector, useDispatch } from 'react-redux'; import { createSelector } from 'reselect'; import callServerEndpoint from './call-server-endpoint.js'; @@ -12,6 +11,7 @@ CallServerEndpointOptions, } from './call-server-endpoint.js'; import { getConfig } from './config.js'; +import { useSelector, useDispatch } from './redux-utils.js'; import { serverCallStateSelector } from '../selectors/server-calls.js'; import { logInActionSources, diff --git a/lib/utils/redux-utils.js b/lib/utils/redux-utils.js --- a/lib/utils/redux-utils.js +++ b/lib/utils/redux-utils.js @@ -1,8 +1,11 @@ // @flow -import { useSelector as reactReduxUseSelector } from 'react-redux'; +import { + useSelector as reactReduxUseSelector, + useDispatch as reactReduxUseDispatch, +} from 'react-redux'; -import type { AppState } from '../types/redux-types.js'; +import type { AppState, Dispatch } from '../types/redux-types.js'; function useSelector( selector: (state: AppState) => SS, @@ -11,4 +14,8 @@ return reactReduxUseSelector(selector, equalityFn); } -export { useSelector }; +function useDispatch(): Dispatch { + return reactReduxUseDispatch(); +} + +export { useSelector, useDispatch };