From 920e74f7bde2dbcd0b25975c5c60648ae241be84 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 18 Sep 2024 23:06:07 +0700 Subject: [PATCH] replace withOnyx with useOnyx --- src/pages/settings/AboutPage/ConsolePage.tsx | 25 ++++--------------- .../ExitSurvey/ExitSurveyResponsePage.tsx | 18 ++++--------- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/src/pages/settings/AboutPage/ConsolePage.tsx b/src/pages/settings/AboutPage/ConsolePage.tsx index 8fa405ee34df..b156a6c7b2f1 100644 --- a/src/pages/settings/AboutPage/ConsolePage.tsx +++ b/src/pages/settings/AboutPage/ConsolePage.tsx @@ -4,7 +4,7 @@ import {format} from 'date-fns'; import React, {useCallback, useMemo, useRef, useState} from 'react'; import {View} from 'react-native'; import type {ListRenderItem, ListRenderItemInfo} from 'react-native'; -import {withOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; import Button from '@components/Button'; import ConfirmModal from '@components/ConfirmModal'; @@ -33,23 +33,15 @@ import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import type {CapturedLogs} from '@src/types/onyx'; -type ConsolePageOnyxProps = { - /** Logs captured on the current device */ - capturedLogs: OnyxEntry; - - /** Whether or not logs should be stored */ - shouldStoreLogs: OnyxEntry; -}; - -type ConsolePageProps = ConsolePageOnyxProps; - const filterBy = { all: '', network: '[Network]', } as const; type FilterBy = (typeof filterBy)[keyof typeof filterBy]; -function ConsolePage({capturedLogs, shouldStoreLogs}: ConsolePageProps) { +function ConsolePage() { + const [capturedLogs] = useOnyx(ONYXKEYS.LOGS); + const [shouldStoreLogs] = useOnyx(ONYXKEYS.SHOULD_STORE_LOGS); const [input, setInput] = useState(''); const [isGeneratingLogsFile, setIsGeneratingLogsFile] = useState(false); const [isLimitModalVisible, setIsLimitModalVisible] = useState(false); @@ -231,11 +223,4 @@ function ConsolePage({capturedLogs, shouldStoreLogs}: ConsolePageProps) { ConsolePage.displayName = 'ConsolePage'; -export default withOnyx({ - capturedLogs: { - key: ONYXKEYS.LOGS, - }, - shouldStoreLogs: { - key: ONYXKEYS.SHOULD_STORE_LOGS, - }, -})(ConsolePage); +export default ConsolePage; diff --git a/src/pages/settings/ExitSurvey/ExitSurveyResponsePage.tsx b/src/pages/settings/ExitSurvey/ExitSurveyResponsePage.tsx index 4d652c94c104..df89a1719ffe 100644 --- a/src/pages/settings/ExitSurvey/ExitSurveyResponsePage.tsx +++ b/src/pages/settings/ExitSurvey/ExitSurveyResponsePage.tsx @@ -1,6 +1,6 @@ import type {StackScreenProps} from '@react-navigation/stack'; import React, {useCallback, useEffect, useState} from 'react'; -import {withOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import FormProvider from '@components/Form/FormProvider'; import InputWrapper from '@components/Form/InputWrapper'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; @@ -34,13 +34,10 @@ import INPUT_IDS from '@src/types/form/ExitSurveyResponseForm'; import type {Errors} from '@src/types/onyx/OnyxCommon'; import ExitSurveyOffline from './ExitSurveyOffline'; -type ExitSurveyResponsePageOnyxProps = { - draftResponse: string; -}; +type ExitSurveyResponsePageProps = StackScreenProps; -type ExitSurveyResponsePageProps = ExitSurveyResponsePageOnyxProps & StackScreenProps; - -function ExitSurveyResponsePage({draftResponse, route, navigation}: ExitSurveyResponsePageProps) { +function ExitSurveyResponsePage({route, navigation}: ExitSurveyResponsePageProps) { + const [draftResponse = ''] = useOnyx(ONYXKEYS.FORMS.EXIT_SURVEY_RESPONSE_FORM_DRAFT, {selector: (value) => value?.[INPUT_IDS.RESPONSE]}); const {translate} = useLocalize(); const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); @@ -182,9 +179,4 @@ function ExitSurveyResponsePage({draftResponse, route, navigation}: ExitSurveyRe ExitSurveyResponsePage.displayName = 'ExitSurveyResponsePage'; -export default withOnyx({ - draftResponse: { - key: ONYXKEYS.FORMS.EXIT_SURVEY_RESPONSE_FORM_DRAFT, - selector: (value) => value?.[INPUT_IDS.RESPONSE] ?? '', - }, -})(ExitSurveyResponsePage); +export default ExitSurveyResponsePage;