Hello! I'm learning clojurescript now and have some problem:
(def click-count (atom 0))
(defn b []
[:div
"The atom " [:code "click-count"] " has value: "
@click-count ". "
[:input {:type "button" :value "Click me!"
:on-click #(swap! click-count inc)}]])
in main-panel
:
(b)
So that's almost work. I have button on my page but it doesn't refresh. First value is 0 and when i click on button value don't changes. It changes only when i clicked some times then re-build it and it shows quantity of clicks. So what i should do to refresh it without re-building?
Replace (b)
with [b]
.
Unrelated things:
- Your code has nothing to do with re-frame - it would be better to ask the question in #reagent
- You can use triple backticks to create whole code blocks
If you use triple backticks as first and last lines of your code, you will get something that looks like this:
(defn x[]
(println "x"))
Replacing doesn't help. What it may be else?
You need to use a reagent/atom
, not a cljs atom
Oh, someone answered this in #reagent already, excellent
would anyone have some recommendations to add syntax highlighting in a preblock in a reframe app?
i don't think that's re-frame specific, but you can checkout highlight.js https://ask.clojure.org/index.php/9068/how-to-use-highlight-js-in-a-shadow-cljs-project
the trick there is to call the highlight function after the reagent component has been rendered
and if you're using shadow-cljs then you can probably easily import this node module and use highlight js as a react component https://github.com/bvaughn/react-highlight.js/
This seems like a simple problem for re-frame, but I am stumped. I want to determine if a field has changed when the user tabs off it, but not before. So if they make a change and then immediately change it back to what it was before leaving the field, I need to recognize that in its final form it is unchanged. Unfortunately, this is a "new item" form so I have no existing source of truth against which to compare. Is there a simple solution I am missing? Thx!
Yep, that is the way we are going. I just had a bug loading the prior value into app-db, and my re-frame is rusty enough that I thought the whole approach was in vain. We spotted the bug and are in good shape now. Thx! @mikethompson
I realize this in part an issue with ReactJS which always wants the form to correspond to app state, IIUC.
By "tab out", do you mean losing focus? If so, you can use the :on-blur
event handler.
It's more related to Reagent/React/JS than to re-frame.
Thx, @p-himik! Yeah, I am in the on-blur to avoid the hyperactive on-change handler, but I cannot tell if we have a net change from any on-change events. Playing with a vanilla atom now, but it feels ugly. 🙂 Yep, definitely a React issue at bottom. I hear they are moving away from imposing their own events scheme, btw.
Ah, I see what you mean. Yeah, I think you will have to store the original value somewhere. Not necessarily an atom.
use :ref, then querySelectorAll on ref and doseq over resulting elems