From 7a128287f210ba3396682665ea9370abee6dab43 Mon Sep 17 00:00:00 2001 From: Deepak <68944868+deepakmali-dgsl@users.noreply.github.com> Date: Wed, 31 Jul 2024 11:13:47 +0530 Subject: [PATCH] Update SettingScreen.tsx Added try/catch for state.SelectedCountry --- app/screens/home/SettingScreen.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/screens/home/SettingScreen.tsx b/app/screens/home/SettingScreen.tsx index b4bc810d9..f548fb205 100755 --- a/app/screens/home/SettingScreen.tsx +++ b/app/screens/home/SettingScreen.tsx @@ -152,10 +152,15 @@ const SettingScreen = (props: any): any => { const countryId = useAppSelector( (state: any) => state.selectedCountry?.countryId, ); - const allCountries = useAppSelector( - (state: any) => - state.selectedCountry.countries != '' ? JSON.parse(state.selectedCountry.countries) : [], - ); + const allCountries = useAppSelector( + (state: any) => { + try { + return state.selectedCountry?.countries !== '' ? JSON.parse(state.selectedCountry?.countries) : []; + } catch (error) { + console.error('Failed to parse countries JSON:', error); + return []; + } + }); const [profileLoading, setProfileLoading] = React.useState(false); const languageCode = useAppSelector( (state: any) => state.selectedCountry?.languageCode, @@ -1254,4 +1259,4 @@ const SettingScreen = (props: any): any => { ); }; -export default SettingScreen; \ No newline at end of file +export default SettingScreen;