From f4d7d4ad40955b59833b674688662922cbc96819 Mon Sep 17 00:00:00 2001 From: Antoine M Date: Fri, 13 Sep 2024 10:39:40 +0200 Subject: [PATCH] fixing flags rerenders --- src/context/UserContext.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/context/UserContext.js b/src/context/UserContext.js index 5a2dc21..e5938b6 100644 --- a/src/context/UserContext.js +++ b/src/context/UserContext.js @@ -39,11 +39,11 @@ export function UserContextProvider({ children }) { const currentCountry = CountriesJSON.find( (countryJson) => countryJson.alpha2 === country.iso.toLowerCase() ); - setCountry({ ...country, label: currentCountry[language.toLowerCase()] }); - console.log("currentCountry", country); - - // eslint-disable-next-line - }, [language]); + // setCountry({ ...country, label: currentCountry[language.toLowerCase()] }); + if (currentCountry && currentCountry[language.toLowerCase()] !== country.label) { + setCountry({ ...country, label: currentCountry[language.toLowerCase()] }); + } + }, [language, country]); function changeUserLanguage(newLanguage) { setLanguage(newLanguage);