This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-06-24
Channels
- # announcements (6)
- # beginners (89)
- # calva (75)
- # cider (37)
- # clj-kondo (1)
- # cljs-dev (19)
- # cljsjs (8)
- # clojars (1)
- # clojure (122)
- # clojure-europe (6)
- # clojure-italy (41)
- # clojure-nl (18)
- # clojure-uk (24)
- # clojurescript (26)
- # cursive (6)
- # data-science (5)
- # datomic (51)
- # emacs (28)
- # fulcro (8)
- # graalvm (13)
- # hoplon (1)
- # immutant (1)
- # jobs (3)
- # joker (1)
- # keechma (43)
- # lambdaisland (1)
- # leiningen (37)
- # midje (1)
- # nrepl (2)
- # off-topic (32)
- # re-frame (3)
- # reagent (24)
- # reitit (5)
- # remote-jobs (1)
- # shadow-cljs (33)
- # sql (7)
- # tools-deps (11)
Does anyone have an example of using reagent.dom.server/render-to-string
? I need to render a piece of html to a string, but cant' figure out how to use the function
here is an example, idk why yours snt working it seems correct https://github.com/reagent-project/reagent/blob/88e9833be9c3135548d760286ffd84d88a0a0489/test/reagenttest/testreagent.cljs#L349
(defn mycomp [a] [:div a])
(reagent.dom.server/render-to-static-markup [mycomp 1])
#object[TypeError TypeError: Cannot set property 'getCurrentStack' of undefined]
I have a question about state and rerendering. Say I have a tree (of clojure data) of state in an atom. I would like to have my whole app state in one atom, because it's nice. Then, if only small thing at the bottom (in a leaf) changes, I would like only a single component to rerender. But if I have all my state in one atom, that won't be possible, because all the other components would either defer the atom to get the data they need each time they are called, or I could pass the tree, and subtrees, down into the children, but since something at the bottom has changed, everything will rerender. So it seems to prevent everything rerendering, I would need to put every little thing in its own atom. But that seems annoying. So, what should I do?
Well, by "everything" I mean almost everything---everything that derefs in the case of using an atom, and in the case of passing arguments, everything that takes an ancestor of the leaf in the data tree.
and just because it’s common, doesn’t mean it’s not a good question 😄 I meant it to mean that people are thinking a lot about this, honestly
the tradeoffs between keeping all your state in one global atom vs. local individual atoms, is being still being explored IMO
local atoms are very performant but have certain dev experience problems, one atom to rule them all is “nice” but you end up still needing to partition your state into these local slices that components can subscribe to
Oh, re-frame looks nice. Thanks for mentioning it @lilactown
Rendering the whole tree shouldn't usually be a problem. Rendering from clojure data (atom) to React elements is very fast, and if DOM don't need changes there isn't much else to do. IF you need to calculate something in the render functions, that can become a performance problem, but in this case you can move the calculations to Reagent reactions or Re-frame subscriptions, so these only run when the input data changes, instead of each render.
It is also possible to use reactions or subscriptions to render components only when part of the tree changes, but that can have it's own problems. (For very large tree, creating thousands of reactions could end up being more expensive than just rendering the whole tree).