Fork me on GitHub

is there any documentation about Reagent components vs "native" react components?


e.g. why there is :render vs :reagent-render


You should generally ignore :render. It corresponds to the raw React render function which only gets this as a parameter. Instead, you should use :reagent-render which will be given props as parameters.


I guess my question is: how are reagent component (component classes?) implemented


I'll spend some more time reading the source, so I'll get there eventually, but if anyone has written things that would help me when trying to understand the code... that would be helpful 🙂


Hi all, I'm working on my first cljs project, and I'm using reagent. I used the lein reagent template and have three src subdirectories: cljs, clj, and cljc. In cljs I have projname/core.cljs, and charts/charts.cljs, where I use highcharts. The charts are working great, but now it's time for me to actually pull the data from the db to give to the charts. Where should this code go? I'd like to put it in a "db" folder but not sure whether this should be clj, or cljc ... and how to then :require it from my charts.cljs file (just a regular :require [db.db :as db] ....?) Please forgive my ignorance on this; it's a bit different from a regular clojure project and I'm still figuring things out.


What kind of database are you pulling that data from?


@joshjones: I'll assume you have some database on the server side, you will need to implement an API endpoint so your Reagent app can request that data from the server


in handler.clj you find a defroutes routes section


@plexus - thanks for your reply! I have a local mysql database. I have clojure code already written that performs the queries, etc. I just need a way to reference the clojure functions.


the thing is, you can't just "reference" those functions from ClojureScript, they live in separate worlds


your reagent app is compiled to JavaScript and runs in the browser, your database runs on the server


you need to bridge that gap yourself


that makes sense, so what would you recommend for the best way to hook things up?


I see the defroutes routes section, where I have put my other routes


Compojure is already included, those are those routes in handler.clj


I used lein new reagent ... so I think I have these


ok ... I will do some research, and I appreciate you pointing me in the right direction. I'm sure after my research I will have some more questions. Thanks for your patience with a cljs newbie


ring-middleware-format and cljs-http won't be there yet, you'll have to add them to project.clj


actually I would use this one instead of cljs-http


it's a thin wrapper around XhrIO which is all you really need, cljs-http is built on core.async which will makes things more complex than necessary


+1 to @plexus recommendation


I started from lein new reagent reagentnew, then applied these changes. That's all you need


thanks @plexus -- I think a separate sample project like this is a great idea, and then I can integrate it into my existing project


yeah exactly, I know how tricky it can be to get all the moving pieces in the right place the first time


now that I think about it, I used lein new figwheel proj so that I could use figwheel to automatically update upon saving, so that may have muddied my mental waters a bit


but i also see a :figwheel in the reagent project, so it looks like I can also use it with the reagent template


yes, the reagent template includes figwheel. It's pretty standard now for ClojureScript-heavy projects