reagent-project / reagent-cookbook

Examples of how to accomplish specific tasks in a Reagent webapp.
MIT License
839 stars 87 forks source link

Recipes promote use `:render` instead of `:component-function` #12

Closed mike-thompson-day8 closed 9 years ago

mike-thompson-day8 commented 9 years ago

I believe it is a mistake to be promoting the use of :render when callingreagent/create-class

For example, I believe this is a mistake:

(defn home-component []
  (reagent/create-class {:render home                    ;;   <--- use of  :render
                         :component-did-mount home-did-mount}))

A renderer function supplied via :render will only ever be called with one parameter (this) which is a pain when you are writing components which need to take multiple parameters (about 99% of them). Newbies are constantly surprised about not getting their parameters passed into render. I've found myself answering the question steadily over the last year.

The alternative is to use :component-function instead of :render. My write up

Dan's Blessing

gadfly361 commented 9 years ago

Thanks! I updated the recipes to use :component-function instead of :render.

mike-thompson-day8 commented 9 years ago

Thanks!

mike-thompson-day8 commented 9 years ago

I'm really sorry about this, but I've given you bad advice here.

After Dan gave his blessing for ongoing use of :component-function there was much negative comment about the name, and so Dan has instead chosen :reagent-render.

So now we're faced with:

Maybe the cookbook examples should return to using straight :render until after 0.5.0 is released? Promoting :reagent-render is a good idea, but not until it is official.

Sorry again.

gadfly361 commented 9 years ago

Oh, no need to be sorry! I wasn't even aware of :component-function to begin with, so I am glad you brought it up. I agree about promoting it once it is renamed to :reagent-render and official in the next reagent release. Until then, I converted everything back to :render.

gadfly361 commented 9 years ago

Now that reagent 0.5.0 is out, I updated the recipes to use :reagent-render