Fork me on GitHub
#reagent
<
2016-07-15
>
snowell15:07:08

Hey all, I’m upgrading dependencies, and I’m getting a Something is calling a React component directly. Use a factory or JSX instead warning. Google led me to some examples that seemed more specific than I needed. Here’s the code:

(let [html (vis/get-html vis response)
            js (vis/get-js vis response)
            reagent-comp (reagent/create-class
                           (merge {:component-function #(views/main-page html)}
                                  (if js {:component-did-mount js} {})))]
        (reagent/render reagent-comp (.getElementById js/document "app")))

snowell15:07:48

views/main-page is just a function returning a hiccup tree with the passed-in html at the bottom

snowell15:07:36

If I replace :component-function with :reagent-render, I get the same error

snowell15:07:27

🦆 For those finding this in a log somewhere with the same problem, using with-meta like the reagent docs say (instead of following the re-frame doc like I was doing) fixes the issue

snowell15:07:50

If I define reagent-comp as (if js (with-meta #(views/main-page html) {:component-did-mount js}) #(views/main-page html)) then everything’s wonderful

rohit16:07:37

@snowell: you could try (reagent/render [reagent-comp] (.getElementById js/document "app”))

rohit16:07:31

I think the warning is related to this

snowell16:07:43

@rohit That does indeed also work!

snowell16:07:09

I like that better since I still don’t fully understand with-meta 🙂

rohit16:07:17

@snowell: sure. reagent/render expects a either a vector or a react element, where as in your code, you were passing it a ReactClass

snowell16:07:38

I guess before it either worked differently or didn’t care

snowell16:07:50

But that explanation makes lots of sense

rohit16:07:14

Maybe they were less strict earlier.

rohit16:07:46

This has the API documentation

snowell16:07:01

Ah, I was on 0.5.x before

rohit16:07:12

which version are you now on?