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
Also the docs don't mention there is an :f>
shortcut now, see: https://github.com/reagent-project/reagent/blob/master/CHANGELOG.md
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:
[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}]
at the same time this seems to work just fine
[Route {:path "/home" :component (r/reactify-component Home) :exact true}]
I have required ["react-router-dom" :as react-router-dom]
and defined the following
(def Redirect (r/adapt-react-class react-router-dom/Redirect)) (def Route (r/adapt-react-class react-router-dom/Route))
Ideas?
:render #(r/as-element [Redirect {:to "/home"}])
or :render #(r/as-element [:> Redirect {:to "/home"}])
if Redirect
is a React component (and not a Reagent component)
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...
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).
right, I meant, maybe it was correct at some point, otherwise it would not had been written (I want to think) haha
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
maybe once I learn the thing I should try doing something like that 🙂
not sure if the docs on teh doc/ folder are supposed to be deprecated or something
I wish someone knowledgeable would tidy up these docs 😞 Maybe in celebration of 1.0? 🙂
It actually works for me even with reagent 0.10.0
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)
@arttuka that worked. thx man!
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.<anonymous> ([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',
it seems to fail when it loads react-dom
even if the dependency is there, and it's kind of a trivial project for now
I’ve seen this error many times and always forget how it’s fixed
I found some references about this online but none of them seen to apply to my project
what version of figwheel/cljs are you using?
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]}
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 believesure if the loader isn’t compiling and running then it’s gonna have problems
I would try bumping all your deps
and clearing your build cache
maybe start with that first, actually
mm looks like disablin [binaryage/devtools "1.0.2"]
makes it work
would be good to understand why
ah no interesting now the first error is gone but the second is still there
it still doesn't load react-dom properly, even if I cleaned already and hard reloaded, weird
are you excluding cljsjs/react-dom ?
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"]
and I can see the react js file being fetched correctly in the network tab
probably worth asking in #figwheel-main
doesn’t sound like it’s a reagent problem tbh
I would investigate your build config
yeah probably let me try to change a few things