rstack

FAQ

What is rstack?

rstack is a website dedicated to teaching and supporting web development with Clojure/Script.

One of the common complaints about Clojure/Script is that there aren't enough complete examples for beginners. Some people also lament the fact that some libraries aren't updated very often which makes it hard to know if you're using a library that's still supported by the community. My goal with this site is to help with that and hopefully get more people into Clojure/Script as a result.

There also seems to be a common misunderstanding that Reagent and Re-frame are no longer relevant in 2023 as a result of changes in the React ecosystem. I believe the stability of these APIs is an antidote for the complexity of the modern JavaScript stack. That said, starting from scratch and setting up a great developer experience with Clojure/Script can be challenging without the right instructions. That's another reason this site exists.

What ClojureScript bundler should I use? (shadow-cljs, lein-figwheel, figwheel-main, CLJS compiler)

  • shadow-cljs is the most popular CLJS bundler and should be the default for new projects since it provides the smoothest developer experience with hot-reloading and the REPL. It includes support for dealing with almost every weird JavaScript scenario you can think of, plus the maintainer has been really attentive over the years.
  • figwheel-main is an alternative to shadow-cljs with many similar features, but it never quite achieved the same popularity as lein-figwheel. I recommend shadow-cljs over figwheel-main in all scenarios to benefit from the larger community size and more active maintenance.
  • lein-figwheel is the predecessor to figwheel-main and was the most popular way to compile CLJS in the early years. In the post-Clojure-CLI era, lein-figwheel no longer makes sense in many projects and shadow-cljs is a better choice since it supports both the Clojure CLI and Leiningen.
  • The CLJS compiler can be used without a bundler using the official "Quick Start" instructions. That said, I don't recommend anyone actually do this because it's only one small piece of the tooling needed to support an effective CLJS development workflow. Use shadow-cljs instead.

How do I test my Clojure/Script app?

What build tool should I use? (Clojure CLI, Leiningen, Boot)

  • Clojure CLI is the official build tool from the Clojure core maintainers and should be the default for new projects.
  • Leiningen is still a popular choice but I encourage people to migrate to the Clojure CLI if they can since it's the officially supported tool.
  • Boot isn't used much by anyone these days so don't worry about it if you see it mentioned in some older documentation.

What's the best way to learn Reagent/Re-frame?

Check out the Quick Start page.

Is it possible to do server-side rendering (SSR) with Reagent/Re-frame?

Yes! There are a couple possible approaches to SSR in a Reagent/Re-frame app:

  • Write components in CLJC using Rain to render Reagent/Re-frame components on the JVM without React. This has the benefit of fewer dependencies and being able to keep all your code in the same process, making it easier to deploy. The tradeoff is that you can't use this technique to render third-party React components that rely on React itself to do the SSR.
  • If you need to do server-side rendering of third-party React components, you can add a Node.js process to your app which will handle rendering by communicating with your Clojure web server over HTTP. This is a more complicated architecture so it might not be worth it if you care mostly about adding SSR to components that are written in CLJC.

Are Reagent and Re-frame out-of-date in 2023?

No. Reagent and Re-frame are a great choice for making an app today due to the simplicity of the architecture and the mature ecosystem within the Clojure/Script community. In contrast to constant churn of the JavaScript world, the APIs that worked well in 2015 are even more effective today due to their stability over time.

Speaking of churn in the JavaScript world, Reagent/Re-frame can support many key features of React 18 already:

  • Hooks using [:f> component props]
  • Lazy component loading with Suspense and React.lazy
  • Server-side rendering using hydrateRoot

In general, Reagent and Re-frame provide enough tools so you don't have to dig deep into the React ecosystem unless you want to. Many of these features exist to optimize performance, but performance is often not the biggest problem when building a web app. If you don't understand what your code is doing underneath, you risk slowing down when trying to debug issues later on.

If you can keep things simple by sticking to Reagent ratoms (local state) and the Re-frame DB (shared state), you'll benefit from simpler code. When you encounter a bottleneck, you can optimize on a per-component level rather than throwing away the whole Reagent and Re-frame stack.

How do I write idiomatic Clojure/Script code?

  • Focus on data-oriented programming.
  • Keep business logic out of the React components.

How do I set up my editor for Clojure/Script development?

Editors

  • IntelliJ
  • VSCode
  • Vim
  • Emacs

Tools

  • REPL
  • Portal
  • tap>
  • clojure.pprint
  • hasht
  • prn
  • Kaocha
Built by @rads with Rain.