Fork me on GitHub
#missionary
<
2022-06-29
>
martinklepsch21:06:55

I found that I got this error when returning the value from something like ((observe ,,,)) in a React effect hook. When wrapping the value in a (fn [] (cancel-flow)) it works as you’d expect. This seems like React does not recognize what missionary returns as a function?

leonoel09:06:50

interesting, javascript functions are clojure functions but the opposite is not true

leonoel09:06:53

I'm not sure this can be solved without modifying the clojurescript compiler

martinklepsch11:06:38

Maybe a helper that returns #(kill this) could be a workaround?

(get-cancel-fn ((observe)))

martinklepsch11:06:46

Not great admittedly

lilactown14:06:17

you could also have a useEffect helper that checks to see if the return value is an IFn and wraps it in a function

lilactown15:06:05

(defn use-effect
  [f deps]
  (useEffect
   (fn []
     (let [ret (f)]
       (cond
         (ifn? ret) #((ret))
         (nil? ret) js/undefined
         :else ret)))
   deps))

lilactown15:06:37

I think the downside to that is it might be too much of a catch all, e.g. maps implement IFn