heads up, I just changed my github name to lilactown
if you're using git deps, I believe the URLs to repos should still work but they should be updated soon
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 "<http://localhost:9001/api/goals>"
{: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 <http://limeray.web.app/root|limeray.web.app/root>)
in div (created by <http://limeray.web.app/root|limeray.web.app/root>)
in <http://limeray.web.app/root|limeray.web.app/root>
Consider adding an error boundary to your tree to customize error handling behavior.
Visit <https://fb.me/react-error-boundaries> 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)
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
Oh! I did not realized there is non-star one. It works! 🙂
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`.")
([f])
([f deps])
are the aritys.
the star version wants the arguments in the opposite order of the non-start onethe error you're seeing is because it's trying to treat the function as a JS array 😓
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)
it made sense once I knew what the code of use-effect*
looked like 😄
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
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
sure thing! 🙇:skin-tone-2: