This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-17
Channels
- # aws (2)
- # beginners (34)
- # boot (39)
- # cider (28)
- # cljs-dev (2)
- # cljsrn (30)
- # clojure (195)
- # clojure-austin (6)
- # clojure-dev (6)
- # clojure-dusseldorf (1)
- # clojure-france (1)
- # clojure-russia (139)
- # clojure-spec (25)
- # clojure-uk (66)
- # clojurescript (125)
- # community-development (1)
- # core-async (42)
- # cryogen (1)
- # cursive (22)
- # datascript (6)
- # datomic (67)
- # docker (1)
- # emacs (7)
- # events (1)
- # garden (3)
- # hoplon (15)
- # jobs (3)
- # lein-figwheel (10)
- # leiningen (3)
- # luminus (4)
- # mount (2)
- # nginx (1)
- # off-topic (101)
- # om (42)
- # om-next (6)
- # onyx (7)
- # proton (1)
- # protorepl (4)
- # re-frame (15)
- # reagent (30)
- # remote-jobs (1)
- # ring (8)
- # ring-swagger (17)
- # rum (1)
- # spacemacs (2)
- # sql (1)
- # yada (50)
It's there a way for reagent to create a real react component? some component receive component or element as props, for example, RefreshControl
. I can't make it work with reagent.
^ I think that's where adapt-react-class comes into play, and I think you should think in reverse, e.g. convert the react component to work with reagent's hiccup-like forms
maybe you can back read here, probably it answers some of the questions (e.g. use adapt-react-class
for importing react components, and as-element
to return a component)
https://clojurians.slack.com/archives/cljsrn/p1484501499001949
^ click the link so you can read the discussion, after that link are the answers and clarifications
How do you handle a json request in re-natal? I'm getting a blank response ...
(def data (js->clj GET ""))
(defn app-root []
[text (:title data)])
@ejelome You either need to pass :keywordize-keys true
to js->clj
or you can just get the title by string:
; Add this to your requires
(require [goog.object :as obj])
; ... fetch your data
(defn app-root []
[text (obj/get data "title")])
With the later, you can avoid converting the js->clj
, which, as I understand it, can be slow for large/deep objects
here's the full code just in case:
(ns networking.android.core
(:require [reagent.core :as r]
[ajax.core :refer [GET]]
[goog.object :as obj]))
(def ReactNative (js/require "react-native"))
(def app-registry (.-AppRegistry ReactNative))
(def text (r/adapt-react-class (.-Text ReactNative)))
(def data (GET ""))
(defn app-root []
[text (obj/get data "title")])
(defn init []
(.registerComponent app-registry "Networking" #(r/reactify-component app-root)))
I don’t think that HTTP call is sync
most probably you need to pass callback to GET function or at least add some dummy setTimeout
read the docs, I’m not aware about ajax.core at all but JS as a platform doesn’t allow doing sync HTTP requests so most probably callback has to passed somewhere
I actually read the docs of it but getting it mixed with components becomes a challenge
(defn handler [response] (str response))
(def data (clj->js GET "" {:handler handler}))
(defn app-root []
[text (str data)])
well, you handler function doesn’t do anything
it does, but only prints it, it's just to know if it receives something (which it is, it received a stringified callback)
ah, ok. Now just figure how to pass updated data to reagent and it’s done 🙂
many time it helps 🙂
yeah, clojure is like my past time after work, probably too tired to figure things out XD
anyhow, thanks @peterschwarz @petterik and @artemyarulin 😄