This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-02
Channels
- # beginners (98)
- # bigdata (1)
- # bitcoin (1)
- # boot (32)
- # cider (20)
- # cljs-dev (57)
- # cljsrn (130)
- # clojure (93)
- # clojure-dusseldorf (1)
- # clojure-germany (1)
- # clojure-greece (3)
- # clojure-italy (2)
- # clojure-russia (203)
- # clojure-spec (14)
- # clojure-uk (50)
- # clojurescript (127)
- # css (7)
- # cursive (6)
- # data-science (1)
- # datomic (4)
- # emacs (1)
- # events (1)
- # fulcro (8)
- # funcool (12)
- # graphql (7)
- # jobs (1)
- # lein-figwheel (2)
- # luminus (2)
- # off-topic (7)
- # om (16)
- # onyx (4)
- # parinfer (17)
- # pedestal (6)
- # portkey (36)
- # proton (3)
- # re-frame (10)
- # shadow-cljs (140)
- # spacemacs (12)
- # specter (1)
- # sql (1)
- # vim (10)
- # yada (10)
@bcbradley https://github.com/reagent-project/reagent/blob/master/src/reagent/impl/template.cljs#L310
it's a sign that the following object will be interpreted as a React (not reagent) component
it allows you to use native components from RN or from 3rd party js libraries
(def view (r/adapt-react-class (.-View rn)))
[view props ...]
is similar to
[:> view props ...]
it's not exactly the same because 1 will error at load time if rn.View
doesn't exist, whereas 2 will throw at render time
kebab-case instead of CamelCase
or what do you mean?
listView
is the name of the js function/class
was looking for guides, tutorials or documentation about reagent but there doesn't seem to be a lot
i saw ([:> ) in the 0.6 patch and wondered if maybe i was just using an outdated way of getting a native react component, but based on what you've told me they are just similar
functionally equivalent yes
try translating the example from RN docs first
1 by 1
not sure what you mean
https://github.com/drapanjanas/re-natal/blob/master/resources/cljs-reagent6/core.cljs#L13
the JS names are just what they are in JS
it's convenient to def
them to clojurescript names using kebab-case
(sorry I meant kebab-case above)
plus reagent automatically translates props like :font-family
to "fontFamily"
but you can always use the straight react names as well
(defn app-root []
(let [quizzes (subscribe [:get-quizzes])]
(fn []
[view {:style {:flex-direction "column" :margin 40 :align-items "center"}}
[text {:style {:font-size 30 :font-weight "100" :margin-bottom 20 :text-align "center"}} "Oi"]
[button {:title "Press me" :background-color "#555" :on-press #(alert "HELLO!")}]
[flat-list {:data @quizzes
:render-item (fn [{:keys [name]}] [text {} name])}]])))
i was working in re-natal but adding the flat-list element there at the bottom causes things to break
what error do you see?
try using :data (into-array @quizzes)
does it work if you comment out the flat list?
try replacing [text {} name]
with [text "asdf"]
does it work then?
(r/as-element [text name])
solved ✅
can you give me a resource that can help me understand why i needed the r/as-element?
think about it... the function passed as :render-item
is expected to return a React element
but you're returning a PersistentVector
a React element this is not
it can't possibly do that unfortunately
it's one of the things about pure-React interop you need to know about Reagent
unfortunately the docs on Reagent are a bit.. sparse
hm...
i'm doing freelance work for someone and figured i'd give clojurescript a shot for a mobile app
sometimes you need to pass js data structures to RN functions or get JS datastructures back in callbacks
remember to use #js[]
, #js{}
, into-array
, goog.obj/get
to access/pass the data
you don't need to do that for styles and props
reagent handles this automatically
hm they're not very well liked
have some unexpected caveats
avoid if you can
(but I use them sometimes as well)
it's for accessing JS objects by key
instead of (.-property obj)
which will fail if you're using adv compilation
hold on a second the basic dot form for field access fails if you are using an advanced compilation?
rule of thumb is to use gobj/get for "data" as opposed to coe, methods and the like
well it'll be minfied away into
or something like that
that's part of what adv compilation does
check this repo for usage of RN components in reagent: https://github.com/status-im/status-react
it's a larger app so may be hard to grok sometimes but can still be helpful
do ask 🙂
maybe we should start a FAQ
yeah I know the beginning is rough
let's start a faq
@bcbradley I just started a FAQ in the re-natal wiki: https://github.com/drapanjanas/re-natal/wiki/ClojureScript-React-Native-Reagent-re-natal-FAQ
thanks! should i submit an issue or should i put something here if i think of something that would be good to add to the faq?
i might submit a pull request, but i don't think i'd want to do that unless i already had the answer
i guess one thing that might be nice to add to the faq is an explanation of why cljs->js and js->cljs isn't necessarily a good idea
for instance, you said that you don't have to use them in the properties map because reagent will do it for you'
that's really just a convention
but yeah reagent's camel-casing might be a good addition to the faq
feel free to add stuff that you bump into
let's make it a bit easier for the next gal or guy
once we add some more stuff, @mfikes might add a link to the FAQ to http://cljsrn.org
Definitely @pesterhazy, if there is content you’d like to see there, just PR and I’ll put it up there.
cool!
Changed the link to the page: https://github.com/drapanjanas/re-natal/wiki/FAQ
@drapanjanas hope you're ok with me adding a FAQ page to the wiki?
@pesterhazy sure thing!