reagent-project / reagent

A minimalistic ClojureScript interface to React.js
http://reagent-project.github.io/
MIT License
4.74k stars 412 forks source link

`TypeError` when using function components with `r/create-class` with `dom.server/render-to-string` #581

Open p-himik opened 1 year ago

p-himik commented 1 year ago

A weird combination, but seems like nextjournal/clerk would benefit from it. The initial discussion on Slack.

A minimal reproducible example:

(ns app.core
  (:require [reagent.dom.server :as dom.server]
            [reagent.core :as r]))

(r/set-default-compiler! (r/create-compiler {:function-components true}))

(defn root []
  (r/create-class {:reagent-render (fn [] [:span])})
  ;[:span]
  )

(js/console.log (dom.server/render-to-string [root]))

Uncommenting that [:span] makes it work. Rendering to a regular DOM makes it work. Not using function components makes it work.