Fork me on GitHub
#cljsrn
<
2019-10-15
>
vinurs06:10:37

is that cljs-http can used in react-native?

vinurs06:10:24

i used in react-native with shadow-cljs , it output

ReferenceError: cljs_http is not defined
    at eval (eval at <anonymous> (), <anonymous>:1:1)
    at eval ()

lepistane06:10:47

i couldn't make it work so i used native fetch

vinurs07:10:21

it seems that it can work, but i can’t make it work

vinurs07:10:36

@lepistane could u give an example using fetch, how to print the responese

vinurs07:10:47

i use print in .then, it shows #object[Response [object Object]]

lepistane07:10:04

ohh nicee thanks for the link i will have look 😄 @haiyuan.vinurs

(-> (js/fetch "")
         (.then (fn [resp] (.text resp)))
;; u can add .then with prn here
         (.catch (fn [arg] (js/console.error arg)))
       )

vinurs08:10:59

Strange, still print #object[Promise [object Object]]

vinurs09:10:40

(-> (js/fetch "")
    (.then (fn [resp]
             (prn (.text resp))))
    ;; u can add .then with prn here
    (.catch (fn [arg] (js/console.error arg)))
    )
@lepistane do u can prn the resp?

lepistane09:10:07

@haiyuan.vinurs

(-> (js/fetch "")
         (.then (fn [resp] (.text resp)))
         (.then (fn [txt] (println txt)))
         (.catch (fn [arg] (js/console.error arg))))

vinurs12:10:27

@lepistane i tested this code in react-native, it works, so cljs-http can work in react-native

(ns app.events
  (:require [cljs-http.client :as http]
            [re-frame.core :as rf]
            [cljs.core.async :refer [go <!]]
            ))

(go (let [response (<! (http/get
                        ""
                                 {:with-credentials? false
                                  :query-params {"since" 135}}
                                 ))]
      (prn (:status response))
      (prn (map :login (:body response)))))

👍 12
joshmiller18:10:45

@haiyuan.vinurs Glad to see it’s working.