clojure - Why does Reagent render JSON in three ways? -
i trying render json data api call in clojurescript/reagent. when use js/alert see json expect: ["sue" "bob"]
(defn- call-api [endpoint] (go (let [response (<! (http/get endpoint))] (:names (:body response))))) ;; ------------------------- ;; views (defn home-page [] [:div (call-api "/api/names")]) this how i'm referencing libraries (in case there's problem there).
(ns myapp.core (:require [reagent.core :as reagent :refer [atom]] [reagent.session :as session] [cljs-http.client :as http] [cljs.core.async :refer [<! >!]] [secretary.core :as secretary :include-macros true] [accountant.core :as accountant]) (:require-macros [cljs.core.async.macros :refer [go]])) but when log console, long hash looks nothing api response. browser renders "00000000000120".
- why these results differ? (browser, alert window, console message)
- how can i'm seeing in alert window render on page?
when call call-api going return go block. instead of trying consume go block directly in reagent function, instead update return value in ratom.
(def app-state (atom)) ;; ratom (defn- call-api [endpoint] (go (let [response (<! (http/get endpoint))] (reset! app-state (:names (:body response)))))) (defn home-page [] [:div @app-state]) (defn main [] (call-api))
Comments
Post a Comment