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
However these values are not reactive, e.g. locale value. If I navigate to localized url from /en/slug to /fr/slugusing the usual Gatsby Link components, the page is being routed to the new address without reload but locale value remains the same it was before - en in my example while URL is /fr/slug already. My expectation is that locale value coming from the hook is changed reactively as the page is navigated to other language URLs.
This happens because the values are cached with useState here:
So in theory it's not a problem to fix that and pass locale down without caching. So is there any particular reason to cache it not update as locale from pageContext updates?
The text was updated successfully, but these errors were encountered:
That seems like a massive oversight, the correct fix would be to use useMemo I think. That preserves the caching but will invalidate when locale changes. I think Gatsby has this built in now, which is why I'm not actively working on this anymore
However I don't really like the convention they used in that plugin, where the localized files have to be created one copy per locale. That's why I was looking for alternative and ended up using your plugin instead of the one from the doc.
But I don't know too much about Gatsby so maybe I'm missing some major piece here. However as for what it seems to me know your plugin is a viable and meaningful alternative to the plugin from the official docs so maybe could potentially be mentioned there along with the other one.
The plugin provides React hook
useLocalization
. It is used like this:However these values are not reactive, e.g.
locale
value. If I navigate to localized url from/en/slug
to/fr/slug
using the usual GatsbyLink
components, the page is being routed to the new address without reload butlocale
value remains the same it was before -en
in my example while URL is/fr/slug
already. My expectation is thatlocale
value coming from the hook is changed reactively as the page is navigated to other language URLs.This happens because the values are cached with
useState
here:gatsby-plugin-internationalization/src/LocalizationContext.js
Line 17 in 3d69bd3
But the value that comes from
pageContext
is actually reactive and changes as URL changes:So in theory it's not a problem to fix that and pass
locale
down without caching. So is there any particular reason to cache it not update aslocale
frompageContext
updates?The text was updated successfully, but these errors were encountered: