Fork me on GitHub
#re-frame
<
2023-08-12
>
Nim Sadeh22:08:44

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-himik22:08:29

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 Sadeh22:08:36

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

Nim Sadeh22:08:11

Doing that fixed the warning though!

Nim Sadeh22:08:24

It's the only subscribe call in the entire app

hifumi12323:08:35

reagent's hiccup compiler uses vectors to represent elements

hifumi12323:08:54

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

hifumi12323:08:24

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

👍 2
Nim Sadeh00:08:32

Understood, thanks!