-
hi 👋 the i got bitten by this when i noticed my page titles wouldn't dynamically update when using code like this: const { $t } = useFluent();
useTitle($t("loading")); // no error but does not actually work when switching languages … while this works fine: const { $t } = useFluent();
useTitle(() => $t("loading")); // works instantly when switching languages this may not be a bug per se because a i'm wondering if there's a design choice behind this which i may not have understood? or maybe i'm just ‘holding it wrong’? in which case, please tell me what i should do differently? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, The return type of Having
For example, let's say that you want to add site name to your page titles: useTitle(`${$t("loading")}-${site}`); // not reactive Reactive result of useTitle(`${$t("loading").value}-${site}`); // not reactive So you are still forced to use useTitle(() => `${$t("loading").value}-${site}`); // reactive, but ugly That is why we have the current design: useTitle(() => `${$t("loading")}-${site}`); // reactive, and looks fine The nicest solution would, probably, be a better |
Beta Was this translation helpful? Give feedback.
Hi,
The return type of
$t
is a string, and yes, it cannot be reactive. But$t
method itself is reactive, as you found out by using() => $t()
.Having
$t
returnRef<string>
would be less convenient, forcing.value
usage everywhere.computed(() => $t('...'))
- this is not a workaround, but a normal use case.Most of the time when you are in
script setup
you are already in some kind of computed context, and you can use$t
directly.For example, let's say that you want to add site name to your page titles:
Reactive result of
$t
will not help you in this case:So you are still forc…