This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-14
Channels
- # announcements (7)
- # aws (1)
- # babashka (1)
- # beginners (19)
- # calva (9)
- # clj-commons (4)
- # clj-kondo (64)
- # clj-on-windows (27)
- # cljsrn (12)
- # clojure (127)
- # clojure-bay-area (3)
- # clojure-europe (25)
- # clojure-hungary (7)
- # clojure-nl (1)
- # clojure-norway (9)
- # clojure-spec (5)
- # clojure-survey (2)
- # clojure-uk (22)
- # community-development (5)
- # core-async (19)
- # cursive (29)
- # datascript (8)
- # events (1)
- # fulcro (2)
- # graalvm (3)
- # jobs (1)
- # lsp (155)
- # malli (18)
- # nbb (6)
- # off-topic (86)
- # pathom (2)
- # rdf (18)
- # re-frame (9)
- # releases (2)
- # scittle (24)
- # shadow-cljs (33)
- # xtdb (4)
I’m trying to integrate a JS translation library into a reframe component. It provides a t
function that’s easy enough to put in the app-db
and provide as a subscription. The problem is that I need to re-render after e.g. a languageChanged
event. The problem is that even though it’s easy enough to update t
in the app-db, that doesn’t actually change t
s value so the page doesn’t actually re-render. What’s the best way to hack around something like that? I’d like all the components that depend on t
to rerender
I wouldn't put t
in the app-db itself, I think. Unless it's create dynamically.
You can store some data structure in the app-db that relies on the language, like {:lang :en_us, :t t}
, the :t
would be the same but :lang
would change.
Then you'd have some sub like
(rf/reg-sub :i18n-data
(fn [db _]
;; That map from the above.
(:i18n-data db)))
And an util function like
(defn <t []
(:t @(rf/subscribe [:i18n-data])))
And instead of using the :i18n-data
subscription directly, you'd use the <t
function.t
isn’t created dynamically; the library is basically written as a singleton that it’s an instance member of.
Ah, then that map can be just {:lang :en_us}
and the function can be
(defn <t []
@(rf/subscribe [:i18n-data])
t)
There’s some react bindings to it that offer const { t, i18n } = useTranslation();
as a hook; I was trying to match that kind of user experience
Doesn’t that involve messing around with some stuff to get it to compile to functional components?
I was under the impression that it’s something that doesn’t work by default
Kinda. Three approaches:
• Make all your components function ones by default
• For each component that needs a hook, create a thin wrapper and use :f>
• For each component that needs a hook, use a different library like https://github.com/lilactown/helix
But I've never done it myself so no clue how well it ends up working with ratoms in practice.