You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* I18n object from `@lingui/core` is the single source of truth for all i18n related
86
+
* the I18n object passed via props is the single source of truth for all i18n related
61
87
* data (active locale, catalogs). When new messages are loaded or locale is changed
62
-
* we need to trigger re-rendering of LinguiContext.Consumers.
88
+
* we need to trigger re-rendering of LinguiContext consumers.
63
89
*/
64
-
React.useEffect(()=>{
65
-
constupdateContext=()=>{
66
-
latestKnownLocale.current=i18n.locale
67
-
setContext(makeContext())
68
-
}
69
-
constunsubscribe=i18n.on("change",updateContext)
70
-
71
-
/**
72
-
* unlikely, but if the locale changes before the onChange listener
73
-
* was added, we need to trigger a rerender
74
-
* */
75
-
if(latestKnownLocale.current!==i18n.locale){
76
-
updateContext()
77
-
}
78
-
returnunsubscribe
79
-
},[i18n,makeContext])
90
+
constcontextObject=useSyncExternalStore(
91
+
subscribe,
92
+
getSnapshot,
93
+
getSnapshot
94
+
)
80
95
81
-
if(!latestKnownLocale.current){
96
+
if(!contextObject.i18n.locale){
82
97
process.env.NODE_ENV==="development"&&
83
98
console.log(
84
99
"I18nProvider rendered `null`. A call to `i18n.activate` needs to happen in order for translations to be activated and for the I18nProvider to render."+
0 commit comments