This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-24
Channels
- # announcements (5)
- # aws (24)
- # babashka (41)
- # beginners (130)
- # bristol-clojurians (2)
- # calva (39)
- # chlorine-clover (64)
- # cider (30)
- # clojure (202)
- # clojure-belgium (1)
- # clojure-dev (99)
- # clojure-europe (5)
- # clojure-hungary (4)
- # clojure-italy (10)
- # clojure-losangeles (8)
- # clojure-nl (11)
- # clojure-norway (6)
- # clojure-spec (7)
- # clojure-uk (12)
- # clojurescript (52)
- # core-typed (26)
- # cursive (19)
- # data-science (19)
- # datomic (19)
- # duct (10)
- # emacs (17)
- # fulcro (22)
- # graalvm (11)
- # jobs (3)
- # kaocha (28)
- # leiningen (6)
- # lumo (2)
- # malli (10)
- # nrepl (2)
- # off-topic (23)
- # pathom (2)
- # pedestal (7)
- # re-frame (3)
- # reagent (30)
- # reitit (2)
- # remote-jobs (2)
- # shadow-cljs (77)
- # sql (10)
- # test-check (22)
- # tools-deps (37)
- # vscode (1)
- # yada (3)
Hi folk, I'm building a tiny code to use the npm "react-rough" library: https://www.npmjs.com/package/react-rough My goal is to get the basic example works: display a sketchy rectangle. I have basically this function:
(ns acme.frontend.app
(:require [reagent.core :as reagent]
["react-rough" :as reactrough]
["react-rough" :refer [Rectangle]]
))
[...]
(defn mount-page []
(reagent/render
[:reactrough
[:Rectangle {:x 15 :y 15 :width 90 :height 80 :fill "red"}]]
(.getElementById js/document "root")))
I use shadow-cljs to build the project. The compilation passed successfully, so import issue, but I don't get the rectangle displayed on the page... See on the following picture:same for Rectangle
. with :reactrough
you just get an actual <reactrough ..>
html element as you see in your elements inspector
I tried with
[:> reactrough
[:> Rectangle {:x 15 :y 15 :width 90 :height 80 :fill "red"}]]
But still don't get the rectangle 😞With this code
[:reactrough
(reagent.core/reactify-component
[:Rectangle {:x 15 :y 15 :width 90 :height 80 :fill "red"}])
]
The "Rectangle" tag is not generated anymore....Also because it's the first time I see this syntax, so I try with and without :>
because I don't know what it means...
It's syntax sugar for reagent.core/adapt-react-class
. You can find it in the Reagent documentation.
Do you know where I can find code example of use of react component from a npm library please?
OK, I was wrong about using reactify-component
- since you don't pass a callback there, it's not needed.
The only thing that you need to change is the import. Replace ["react-rough" :as reactrough]
with ["react-rough" :default reactrough]
.
You can find some things here https://github.com/reagent-project/reagent-cookbook and here https://github.com/reagent-project/reagent/tree/master/examples/ Some of the stuff is outdated though.
Thank you for all the information @U2FRKM4TW 😉
@U2FRKM4TW how exactly?
Your UI is essentially a state machine, maybe with some peculiarities. Figure out the states where the component would be unmounted and where you would want to prevent that. And then either avoid those states or place some guards there.
Hello, I am trying to get CKEditor react component to work.
(ns simple.core
(:require [reagent.core :as reagent]
[re-frame.core :as rf]
[clojure.string :as str]
[simple.routes :as routes]
["ckeditor4-react" :as ck :default CKEditor]
))
(defn ui []
[:div
[:> CKEditor]]
)
But am getting error:
react-dom.development.js:12405 Uncaught Error: Assert failed: Expected React component in: [:> nil]
(in simple.core.ui)
(or (string? comp) (fn? comp))
at Object.reagent$impl$template$vec_to_elem [as vec_to_elem] (template.cljs:312)
at Object.reagent$impl$template$as_element [as as_element] (template.cljs:329)
at template.cljs:403
at core.cljs:5598
at core.cljs:5598
at Object.cljs$core$IKVReduce$_kv_reduce$arity$3 (core.cljs:5602)
at Object.cljs$core$_kv_reduce [as _kv_reduce] (core.cljs:700)
at Object.cljs$core$reduce_kv [as reduce_kv] (core.cljs:2543)
at reagent$impl$template$make_element (template.cljs:401)
at Object.reagent$impl$template$native_element [as native_element] (template.cljs:285)
Check out https://github.com/madhat2r/shadow-re-frame-simple-example to reproduceYour :require
is incorrect. Most likely, you have to use :as CKEditor
. Or maybe :refer CKEditor
.
I have tried it all ways :refer CKEditor
and :as ck
but according to the translation table https://shadow-cljs.github.io/docs/UsersGuide.html#js-deps and the CKeditor docs https://ckeditor.com/docs/ckeditor4/latest/guide/dev_react.html the form should be :default CKEditor
Well if I use :as CKEditor
it works with [:> CKEditor]
but shouldn't that be [:> CKEditor/CKEditor]
that is confusing to me, what am I missing?
It's probably the issue with :default
: https://shadow-cljs.github.io/docs/UsersGuide.html#_about_default_exports
thank you @U2FRKM4TW that is correct. I missed that in the docs.