re-frame

Nim Sadeh 2023-08-12T22:16:44.255289Z

I am getting WARN re-frame: Subscribe was called outside of a reactive context.`` and I am not sure why. I have this code:

(defn render-friend
  [friend]
  (let [name (:name friend)
        id (:id friend)]
    [:> rn/Text {:key id :style {:font-weight :normal
                                 :font-size   16
                                 :color       :blue}}
     name]))

(defn friends-list
  []
  (let [friends @(subscribe [:friends])]
    [:> rn/ScrollView (map render-friend friends)]))

(defn main-view
  []
  [:> rn/View {:style {:background-color :white
                       :flex 1}}
   [:> rn/View {:style {:flex 1}}
    [:> MapView]]
   [:> AnimatedBlock
    (friends-list)]])
Animated block is a pure JS component that takes children as its only prop. It does complicated layout/styling stuff so it was easier to copy paste examples in JS.

p-himik 2023-08-12T22:19:29.646209Z

Are you sure it comes from this particular subscribe call? Also, you probably shouldn't be calling (friends-list) like that. Try [friends-list] instead.

Nim Sadeh 2023-08-12T22:32:36.188799Z

Why is that? It's a function. Is that a special reagent thing?

Nim Sadeh 2023-08-12T22:33:11.952129Z

Doing that fixed the warning though!

Nim Sadeh 2023-08-12T22:33:24.077969Z

It's the only subscribe call in the entire app

hifumi123 2023-08-12T23:15:35.897799Z

reagent's hiccup compiler uses vectors to represent elements

hifumi123 2023-08-12T23:15:54.718609Z

(friends-list) calls the function and returns the value in the parent component

hifumi123 2023-08-12T23:16:24.624119Z

[friends-list] instructs reagent to produce a new component with its own render function, using the results of (friends-list)

👍 1
Nim Sadeh 2023-08-13T00:08:32.755579Z

Understood, thanks!