reagent

A minimalistic ClojureScript interface to React.js http://reagent-project.github.io/
whoops 2020-08-04T00:31:49.101700Z

I think may've confused yourself. You only want to use the compiler if you want to change what Reagent generates (i.e. make it generate functional components by default). If you just want one functional component that's overkill. See the sections "Functional Components" and "Hooks" here: https://cljdoc.org/d/reagent/reagent/1.0.0-alpha2/doc/tutorials/react-features

whoops 2020-08-04T00:37:03.102Z

Also the docs don't mention there is an :f> shortcut now, see: https://github.com/reagent-project/reagent/blob/master/CHANGELOG.md

Hobgoblin 2020-08-04T08:29:48.104700Z

Hello, I'm porting existing TSX code to CLJS and while mostly successful it seems I have a hard time writing this """<Route exact path="/" render={() => <Redirect to="/home" />} />""" in CLJS. I have already tried the following:

Hobgoblin 2020-08-04T08:33:06.106200Z

[Route {:path "/" :render #(r/reactify-component [Redirect {:from "/" :to "/home"}]) :exact true}] [Route {:path "/" :render (fn [_] [:> js/Redirect {:to "/home"}]) :exact true}]]]])) [Route {:path "/" :render (fn [_] (r/reactify-component [#'react-router-dom/Redirect {:to "/home"}])) :exact true}] [Route {:path "/" :render (fn [_] [RootRedirectDerivedFromRedirect {:to "/home"}]) :exact true}] [:> react-router-dom/Route {:path "/" :render #([:> react-router-dom/Redirect {:to "/home"}]) :exact true}] [:> react-router-dom/Route {:path "/" :render (fn [_] [:> react-router-dom/Redirect {:to "/home"}]) :exact true}]

Hobgoblin 2020-08-04T08:33:20.106500Z

at the same time this seems to work just fine

Hobgoblin 2020-08-04T08:33:32.106700Z

[Route {:path "/home" :component (r/reactify-component Home) :exact true}]

Hobgoblin 2020-08-04T08:34:22.107100Z

I have required ["react-router-dom" :as react-router-dom]

Hobgoblin 2020-08-04T08:34:39.107400Z

and defined the following

Hobgoblin 2020-08-04T08:34:40.107600Z

(def Redirect (r/adapt-react-class react-router-dom/Redirect)) (def Route (r/adapt-react-class react-router-dom/Route))

Hobgoblin 2020-08-04T08:34:53.107800Z

Ideas?

arttuka 2020-08-04T09:12:14.108700Z

:render #(r/as-element [Redirect {:to "/home"}])

arttuka 2020-08-04T09:12:43.109300Z

or :render #(r/as-element [:&gt; Redirect {:to "/home"}]) if Redirect is a React component (and not a Reagent component)

EmmanuelOga 2020-08-04T09:37:26.109800Z

fwiw I'm trying the example here: https://github.com/reagent-project/reagent/blob/master/doc/UsingSquareBracketsInsteadOfParens.md#appendix-2 where it is supposed to fail, and it works...

jsn 2020-08-05T09:10:38.132100Z

Well, my guess would be that that specific one at least is not just outdated, it seems just plain wrong (as in: I have doubts Reagent ever behaved that way).

EmmanuelOga 2020-08-05T23:47:15.132700Z

right, I meant, maybe it was correct at some point, otherwise it would not had been written (I want to think) haha

EmmanuelOga 2020-08-05T23:47:48.132900Z

would be awesome to have some sort of build for the docs: if you use a piece of code as an example, should be extracted from a test suite or something

EmmanuelOga 2020-08-05T23:48:04.133100Z

maybe once I learn the thing I should try doing something like that 🙂

jsn 2020-08-05T23:51:17.133300Z

cf. https://github.com/seancorfield/readme

1👍
EmmanuelOga 2020-08-04T09:37:59.110100Z

not sure if the docs on teh doc/ folder are supposed to be deprecated or something

EmmanuelOga 2020-08-04T09:38:41.110300Z

I wish someone knowledgeable would tidy up these docs 😞 Maybe in celebration of 1.0? 🙂

jsn 2020-08-04T10:46:12.110500Z

It actually works for me even with reagent 0.10.0

jsn 2020-08-04T10:56:27.110700Z

I'm having trouble coming up with an interpretation of "Appendix 2" that would not be hopelessly incorrect (but then again, I don't know much about Reagent)

Hobgoblin 2020-08-04T13:58:21.111100Z

@arttuka that worked. thx man!

2020-08-04T15:56:24.111500Z

has anyone seen this error before?

[Figwheel] figwheel-main.edn is valid \(ツ)/
[Figwheel] Compiling build dev to "resources/public/cljs-out/dev-main.js"
internal/modules/cjs/loader.js:1088
  throw err;
  ^

Error: Cannot find module '@cljs-oss/module-deps'
Require stack:
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1085:15)
    at Function.Module._load (internal/modules/cjs/loader.js:928:27)
    at Module.require (internal/modules/cjs/loader.js:1145:19)
    at require (internal/modules/cjs/helpers.js:75:18)
    at [eval]:8:13
    at Script.runInThisContext (vm.js:132:18)
    at Object.runInThisContext (vm.js:315:38)
    at Object.&lt;anonymous&gt; ([eval]-wrapper:10:26)
    at Module._compile (internal/modules/cjs/loader.js:1256:30)
    at evalScript (internal/process/execution.js:98:25) {
  code: 'MODULE_NOT_FOUND',

2020-08-04T15:56:32.111900Z

it seems to fail when it loads react-dom

2020-08-04T15:56:43.112400Z

even if the dependency is there, and it's kind of a trivial project for now

lilactown 2020-08-04T15:56:59.113100Z

I’ve seen this error many times and always forget how it’s fixed

2020-08-04T15:57:06.113400Z

I found some references about this online but none of them seen to apply to my project

lilactown 2020-08-04T15:57:11.114Z

what version of figwheel/cljs are you using?

2020-08-04T15:58:13.114300Z

the deps are just

:dependencies [[org.clojure/clojure "1.10.0"]
                 [org.clojure/clojurescript "1.10.773"]
                 [org.clojure/core.async  "0.4.500"]
                 [cljs-ajax "0.8.0"]
                 [reagent "0.10.0"]]
and
{:dependencies [[binaryage/devtools "1.0.2"]
                                  [com.bhauman/figwheel-main "0.2.11"]]

                   ;; need to add dev source path here to get user.clj loaded
                   :source-paths ["src" "dev"]
                   ;; need to add the compiled assets to the :clean-targets
                   :clean-targets ^{:protect false} ["resources/public/cljs-out"
                                                     :target-path]}

2020-08-04T16:01:05.114900Z

the error I eventually get in the browse is just

dom.cljs:16 Uncaught TypeError: Cannot read property 'render' of undefined
    at reagent$dom$render_comp (dom.cljs:16)
    at Function.cljs$core$IFn$_invoke$arity$3 (dom.cljs:41)
    at reagent$dom$render (dom.cljs:27)
    at Function.cljs$core$IFn$_invoke$arity$2 (dom.cljs:36)
    at reagent$dom$render (dom.cljs:27)
but that's simply because react-dom was not imported properly I believe

lilactown 2020-08-04T16:03:15.115800Z

sure if the loader isn’t compiling and running then it’s gonna have problems

lilactown 2020-08-04T16:04:19.116Z

I would try bumping all your deps

lilactown 2020-08-04T16:04:39.116300Z

and clearing your build cache

lilactown 2020-08-04T16:04:45.116600Z

maybe start with that first, actually

2020-08-04T16:05:11.116800Z

mm looks like disablin [binaryage/devtools "1.0.2"] makes it work

2020-08-04T16:05:29.117500Z

would be good to understand why

2020-08-04T16:07:58.118300Z

ah no interesting now the first error is gone but the second is still there

2020-08-04T16:08:04.118700Z

it still doesn't load react-dom properly, even if I cleaned already and hard reloaded, weird

lilactown 2020-08-04T16:10:57.120100Z

are you excluding cljsjs/react-dom ?

2020-08-04T16:12:11.120400Z

no no it's definitively there

[reagent "1.0.0-alpha2"]
   [cljsjs/react-dom-server "16.13.0-0"]
   [cljsjs/react-dom "16.13.0-0"]
   [cljsjs/react "16.13.0-0"]

2020-08-04T16:12:36.121100Z

and I can see the react js file being fetched correctly in the network tab

lilactown 2020-08-04T16:17:57.122600Z

probably worth asking in #figwheel-main

lilactown 2020-08-04T16:18:19.122900Z

doesn’t sound like it’s a reagent problem tbh

lilactown 2020-08-04T16:18:41.123400Z

I would investigate your build config

2020-08-04T16:21:28.123600Z

yeah probably let me try to change a few things