Fork me on GitHub
#helix
<
2020-08-08
>
lilactown19:08:12

heads up, I just changed my github name to lilactown

lilactown19:08:31

if you're using git deps, I believe the URLs to repos should still work but they should be updated soon

jaime21:08:59

Hello, what am I doing wrong here? I'm trying to get an array of map in the response body and display them. I can see the log of the response body, but not the console.log inside the for

(defnc list-view []
  (let [[state set-state] (hooks/use-state '())]
    (hooks/use-effect*
      :once
      (go (let [response (<! (http/get ""
                                       {:with-credentials? false}))]
            (println "RESPONSE BODY " (:body response))
            (set-state (:body response)))))

    ($ :div "List of goals")
    (for [goal state]
      (do (js/console.log "goal for " goal)
          ($ :div (:title goal))))))
console log
RESPONSE BODY  [{:description goal desc 1, :updated-at 2020-08-08T20:54:30Z, :installment-amount 1000, :target-date 2021-09-01T00:00:00Z, :title goal 1, :id 4fffed2e-9e7f-4b1a-a760-79b40a37cd27, :start-date 2020-08-01T00:00:00Z, :created-at 2020-08-08T20:54:30Z, :wallet-id 968d8164-b864-441f-804b-7ade37ce112f, :target-amount 13000} {:description goal desc 2, :updated-at 2020-08-08T20:54:30Z, :installment-amount 1000, :target-date 2021-09-01T00:00:00Z, :title goal 2, :id cdfc0783-899f-4ad0-aa64-e903702824cc, :start-date 2020-08-01T00:00:00Z, :created-at 2020-08-08T20:54:30Z, :wallet-id 968d8164-b864-441f-804b-7ade37ce112f, :target-amount 13000}]
console errors
Uncaught Error: [object Object] is not ISeqable
    at Object.cljs$core$seq [as seq] (core.cljs:1251)
    at Object.cljs$core$to_array [as to_array] (core.cljs:3662)
    at Function.eval [as cljs$core$IFn$_invoke$arity$2] (hooks.cljc:173)
    at limeray.web.route/list-view (route.cljs:94)
    at renderWithHooks (react-dom.development.js:16261)
    at beginWork$1 (react-dom.development.js:18795)
    at HTMLUnknownElement.callCallback (react-dom.development.js:337)
    at Object.invokeGuardedCallbackImpl (react-dom.development.js:386)
    at invokeGuardedCallback (react-dom.development.js:441)
    at beginWork$$1 (react-dom.development.js:25781)
The above error occurred in the <limeray.web.route/list-view> component:
    in limeray.web.route/list-view (created by )
    in div (created by )
    in 

Consider adding an error boundary to your tree to customize error handling behavior.
Visit  to learn more about error boundaries.
console warning
error when calling lifecycle function limeray.web.core/after-load Error: [object Object] is not ISeqable
    at Object.cljs$core$seq [as seq] (core.cljs:1251)
    at Object.cljs$core$to_array [as to_array] (core.cljs:3662)
    at Function.eval [as cljs$core$IFn$_invoke$arity$2] (hooks.cljc:173)
    at limeray.web.route/list-view (route.cljs:94)
    at renderWithHooks (react-dom.development.js:16261)
    at beginWork$1 (react-dom.development.js:18795)
    at HTMLUnknownElement.callCallback (react-dom.development.js:337)
    at Object.invokeGuardedCallbackImpl (react-dom.development.js:386)
    at invokeGuardedCallback (react-dom.development.js:441)
    at beginWork$$1 (react-dom.development.js:25781)

lilactown21:08:16

hmm, well first thing I notice is you're use use-effect*. I think you'll want to use use-effect (no star) use-effect* should only be used for weird, advanced use-cases

jaime21:08:53

Oh! I did not realized there is non-star one. It works! 🙂

lilactown21:08:59

you'll notice that the docstring for use-effect* is different than use-effect:

(defn use-effect*
     "Like react/useEffect.  See `use-effect` for details on what `f`'s return values.  See namespace doc for `deps`.")

lilactown21:08:40

([f])
([f deps])
are the aritys. the star version wants the arguments in the opposite order of the non-start one

lilactown21:08:59

the error you're seeing is because it's trying to treat the function as a JS array 😓

jaime21:08:30

Oh ok, just curious, does the error below tells that error you mentioned?

at Object.cljs$core$seq [as seq] (core.cljs:1251)
    at Object.cljs$core$to_array [as to_array] (core.cljs:3662)
    at Function.eval [as cljs$core$IFn$_invoke$arity$2] (hooks.cljc:173)
    at limeray.web.route/list-view (route.cljs:94)

lilactown21:08:06

it made sense once I knew what the code of use-effect* looked like 😄

lilactown21:08:42

it doesn't tell me immediately what the issue was. but the use of use-effect* looked funny (as opposed to use-effect), and when I read the source of use-effect* it made sense

jaime21:08:11

I wish the cljs error messages to be more helpful, I wonder how can I improve deciphering errors 😆 Btw, thanks a lot! Appreciate the prompt response

lilactown21:08:53

sure thing! 🙇:skin-tone-2: