I’m building a website with ClojureScript, reagent, re-frame, and bootstrap. I’m trying…
- User
I’m building a website with ClojureScript, reagent, re-frame, and bootstrap. I’m trying to get a dynamically updating barcode by implementing JSBarcode. Here is my code:
(ns ui.new (:require [“reactstrap” :as rs] [“jsbarcode” :as barcode] [finance.core.calculation :refer [force-rounding]] [formatters :as formatters] [utils.core :refer [throw-exception]] [cljs.pprint :refer [cl-format]] [clojure.string :as string] [goog.dom :as gdom] [goog.style :as gstyle] [reagent.core :as ra] [reagent.dom :as rdom] [“react-dom” :refer (createPortal)]))
(defn barcode-component [value barcode-id] (barcode (.getElementById js/document barcode-id) (if (seq value) value 0) {:format "CODE128" :lineColor "#000000" :width 2 :height 40 :displayValue true}))
(defn barcode-render [value] (let [barcode-id (str "barcode-" (random-uuid))] (js/console.log (str "Received value in barcode-render:" value)) (ra/create-class {:component-did-mount #(barcode-component value barcode-id) :component-did-update (fn [_] (println (str "Updating barcode to: " value)) (barcode-component value barcode-id)) :reagent-render (fn [] [:svg {:id barcode-id}])})))
I’m calling it like so in another file:
(defn- scancode-section [] (let [scan-code (rf/subscribe [:inventory-edit/get-form-field :scan-code])] [:div [ui/row row-config [label-col {:class "col-md-3 col-sm-6 col-6 justify-content-end"} "Scanning Code"] [input-col {:class "col-md-3 col-sm-6 col-6 justify-content-end"} [text-input-field :scan-code]]] [ui/col {:class "col-md-3 col-sm-6 col-6"} [:p (str @scan-code)] ; check value is updating correctly [new/barcode-render (str @scan-code)]]]))
The values seem to be updated as per the commented line, but the rendered barcode itself is not dynamically updating. I can see in the log "Updating barcode to: " but no value when the line is typed. I'm wondering what needs to be done to the barcode-render function to have it refresh on update.
- Assistant
- User
Nothing. It still seems to pass through the value on hot-reload.
- Assistant