diff --git a/package-lock.json b/package-lock.json index 22b770ef9913..90ee6cb713be 100644 --- a/package-lock.json +++ b/package-lock.json @@ -109,7 +109,7 @@ "react-native-modal": "^13.0.0", "react-native-nitro-modules": "0.26.2", "react-native-nitro-sqlite": "9.1.10", - "react-native-onyx": "2.0.126", + "react-native-onyx": "2.0.127", "react-native-pager-view": "6.5.3", "react-native-pdf": "6.7.3", "react-native-performance": "^5.1.4", @@ -34002,9 +34002,9 @@ } }, "node_modules/react-native-onyx": { - "version": "2.0.126", - "resolved": "https://registry.npmjs.org/react-native-onyx/-/react-native-onyx-2.0.126.tgz", - "integrity": "sha512-SnRG9wJMEY78A5soCOz9h9RqQe+GVSzQb+jkCNJjRwqVYVuWBiMkRcIPPxXQDOJ6JYZMWqPBctB9vKrg62P6Bg==", + "version": "2.0.127", + "resolved": "https://registry.npmjs.org/react-native-onyx/-/react-native-onyx-2.0.127.tgz", + "integrity": "sha512-D5EeJspj6jjL10DclBbdIGVyqInSzwyzTZDejt6+SJxThk3zTbEClddkp6gXD7T9vilhIEi7+xXYkUvD/SO75w==", "license": "MIT", "dependencies": { "ascii-table": "0.0.9", diff --git a/package.json b/package.json index fb36e992052c..ac990b2b74c6 100644 --- a/package.json +++ b/package.json @@ -179,7 +179,7 @@ "react-native-modal": "^13.0.0", "react-native-nitro-modules": "0.26.2", "react-native-nitro-sqlite": "9.1.10", - "react-native-onyx": "2.0.126", + "react-native-onyx": "2.0.127", "react-native-pager-view": "6.5.3", "react-native-pdf": "6.7.3", "react-native-performance": "^5.1.4", diff --git a/src/hooks/useMobileSelectionMode.ts b/src/hooks/useMobileSelectionMode.ts index 7d53ad4ee767..fb60d570bae1 100644 --- a/src/hooks/useMobileSelectionMode.ts +++ b/src/hooks/useMobileSelectionMode.ts @@ -4,7 +4,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import useOnyx from './useOnyx'; export default function useMobileSelectionMode() { - const [isSelectionModeEnabled] = useOnyx(ONYXKEYS.MOBILE_SELECTION_MODE, {initialValue: false, initWithStoredValues: false, canBeMissing: true}); + const [isSelectionModeEnabled = false] = useOnyx(ONYXKEYS.MOBILE_SELECTION_MODE, {initWithStoredValues: false, canBeMissing: true}); const initialSelectionModeValueRef = useRef(isSelectionModeEnabled); useEffect(() => { diff --git a/src/hooks/useOnyx.ts b/src/hooks/useOnyx.ts index fcead441a099..4d2930256fb3 100644 --- a/src/hooks/useOnyx.ts +++ b/src/hooks/useOnyx.ts @@ -1,14 +1,14 @@ import {useMemo} from 'react'; +import type {DependencyList} from 'react'; // eslint-disable-next-line no-restricted-imports import {useOnyx as originalUseOnyx} from 'react-native-onyx'; -import type {OnyxCollection, OnyxEntry, OnyxKey, OnyxValue, UseOnyxOptions} from 'react-native-onyx'; +import type {OnyxCollection, OnyxEntry, OnyxKey, OnyxValue, UseOnyxOptions, UseOnyxResult} from 'react-native-onyx'; import {useSearchContext} from '@components/Search/SearchContext'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {SearchResults} from '@src/types/onyx'; type OriginalUseOnyx = typeof originalUseOnyx; -type OriginalUseOnyxReturnType = ReturnType; const COLLECTION_VALUES = Object.values(ONYXKEYS.COLLECTION); const getDataByPath = (data: SearchResults['data'], path: string) => { @@ -25,7 +25,7 @@ const getDataByPath = (data: SearchResults['data'], path: string) => { }; // Helper function to get key data from snapshot -const getKeyData = (snapshotData: SearchResults, key: TKey, initialValue?: TReturnValue): TReturnValue => { +const getKeyData = (snapshotData: SearchResults, key: TKey): TReturnValue => { if (key.endsWith('_')) { // Create object to store matching entries const result: OnyxCollection = {}; @@ -38,15 +38,15 @@ const getKeyData = (snapshotData: SearchResu } result[dataKey] = value as OnyxEntry; }); - return (Object.keys(result).length > 0 ? result : initialValue) as TReturnValue; + return (Object.keys(result).length > 0 ? result : undefined) as TReturnValue; } - return (getDataByPath(snapshotData?.data, key) ?? initialValue) as TReturnValue; + return getDataByPath(snapshotData?.data, key) as TReturnValue; }; /** * Custom hook for accessing and subscribing to Onyx data with search snapshot support */ -const useOnyx: OriginalUseOnyx = (key, options, dependencies) => { +const useOnyx: OriginalUseOnyx = >(key: TKey, options?: UseOnyxOptions, dependencies?: DependencyList) => { const {isOnSearch, currentSearchHash} = useSearchContext(); const useOnyxOptions = options as UseOnyxOptions> | undefined; const {selector: selectorProp, ...optionsWithoutSelector} = useOnyxOptions ?? {}; @@ -71,15 +71,15 @@ const useOnyx: OriginalUseOnyx = (key, options, dependencies) => { const originalResult = originalUseOnyx(snapshotKey, onyxOptions, dependencies); // Extract and memoize the specific key data from snapshot if in search mode - const result = useMemo((): OriginalUseOnyxReturnType => { + const result = useMemo((): UseOnyxResult => { // if it has selector, we don't need to use snapshot here if (!shouldUseSnapshot || selector) { - return originalResult as OriginalUseOnyxReturnType; + return originalResult as UseOnyxResult; } - const keyData = getKeyData(originalResult[0] as SearchResults, key, onyxOptions?.initialValue); - return [keyData, originalResult[1]] as OriginalUseOnyxReturnType; - }, [shouldUseSnapshot, originalResult, key, onyxOptions?.initialValue, selector]); + const keyData = getKeyData(originalResult[0] as SearchResults, key); + return [keyData, originalResult[1]] as UseOnyxResult; + }, [shouldUseSnapshot, originalResult, key, selector]); return result; };