reagent

A minimalistic ClojureScript interface to React.js http://reagent-project.github.io/
yenda 2020-04-27T09:41:12.281600Z

wouldn't it make sense to make functional components the default since it's a major version, breaking change would only affect some specific use cases that can be worked around, and it wouldn't make sense to start a new project without functional components given how important hooks are now in the ecosystem?

juhoteperi 2020-04-27T12:30:11.283Z

Maybe. But there could be some cases I don't know about that don't work.

yenda 2020-04-27T15:24:58.284500Z

at Status we haven't updated reagent for a while it's just not necessary, still using "0.7.0" but we would update for the functional components, but having the compiler option being stateful is more annoying that potential breaking changes

yenda 2020-04-27T15:25:39.285300Z

I think I'll try updating the project this week to see if functional components are breaking anything, but for sure being able to use hooks without hacks is going to be nice

athomasoriginal 2020-04-27T17:07:42.290800Z

> wouldn’t it make sense to make functional components the default since it’s a major version I don’t necessarily agree with this point because up till now, the only option was class components and many aren’t aware of this distinction, so it would be good to have people knowingly opt-in. > only affect some specific use cases that can be worked around Can we confidently say this? > without functional components given how important hooks are now in the ecosystem I like functional components as much as the next person, but I don’t actually think hooks are as widely adopted in the React ecosystem as one would initially think. I would argue these are used among early adopters and well maintained projects, but for many large codebases hooks don’t provide enough of an incentive for them to switch.

👆 1
athomasoriginal 2020-04-27T17:09:51.291500Z

All these points are assuming I understand the current suggestion which is we opt-in to functional components 😉

unbalanced 2020-04-27T21:04:51.293500Z

I'm not a big user of react hooks (maybe I should be? don't even know what I'm missing out on) but the biggest benefit to me would be updating the React and ReactDOM versions so they don't conflict for more modern React component libraries. Even the most recent Reagent I can't use current builds of Material-UI or antd v4

yenda 2020-04-28T07:46:34.295200Z

You don't need hooks at all if you just use cljs with reagent/re-frame, but when you start doing interop and use js libraries, sometimes hooks are unavoidable. For example graphql lib apollo relies on hooks for the queries, and in react-native world you are missing a lot in react-navigation without effects, such as useIsFocused, useSafeArea, useHeaderHeight, useScrollToTop, and all the hooks related to animations

yenda 2020-04-28T07:49:04.295400Z

Also maybe I was doing something wrong but in previous versions of reagent I found it pretty hard to use hooks in components without losing some params in the clj->js->clj conversions (not losing completely but losing namespaces in keywords and sets in vectors)

2020-04-28T08:25:34.295600Z

FWIW, I'm using reagent 0.10 and material-ui 4.9.5 (via the cljsjs packages), works just fine. Not using any hooks, though.

unbalanced 2020-04-28T12:49:49.297100Z

@schaueho gotcha. I'm including material-ui v4 in with npm via webpack/figwheel and I'm getting an error with reactDOM stuff. Let me see if I can replicate real quick...

unbalanced 2020-04-28T13:12:03.297300Z

Here's the issue. I get this error: https://reactjs.org/docs/error-decoder.html/?invariant=321 The minimal code that causes this is:

(def text-area (reagent/adapt-react-class js/window.MaterialUI.TextareaAutosize))

(def main-panel []
  [text-area])
The build was:
yarn add material-ui
yarn webpack
with an index.js (if you're familiar with this build style)
import * as MaterialUI from "@material-ui/core";
window.MaterialUI = MaterialUI;
and a dev.cljs.edn that looks like
^{:watch-dirs ["src"]
  :css-dirs   ["resources/public/css"]
  :npm        {:bundles {"dist/index.bundle.js" "src/js/index.js"}}}
{:main            project.core
 :closure-defines {DEBUG true}
 :output-to       "resources/public/js/compiled/app.js" }

unbalanced 2020-04-28T13:34:06.310500Z

So based on the docs here: https://material-ui.com/getting-started/installation/ you need react >= 16.8 and the version in my /target/public/cljs-out/dev/cljsjs/react-dom/development/react-dom.inc.js is var

ReactVersion = '16.13.0';

unbalanced 2020-04-28T13:58:58.310900Z

wait... I still don't see why that's an issue

unbalanced 2020-04-28T13:59:08.311100Z

anyway I fixed it with the following workaround

unbalanced 2020-04-28T13:59:41.311300Z

import * as MaterialUI from "@material-ui/core";
import * as React from "react";
import * as ReactDOM from "react-dom";

window.MaterialUI = MaterialUI;
window.React = React;
window.ReactDOM = ReactDOM;

unbalanced 2020-04-28T13:59:48.311500Z

and it works now ¯\(ツ)

Jp Soares 2020-04-28T14:00:41.311700Z

What figwheel version are you using? I get an error when passing from figwheel-main 0.2.0 to 0.2.1

unbalanced 2020-04-28T14:24:28.312400Z

squint that's a good question. I'm using cider-jack-in-cljs so I'm not sure what it's using

2020-04-28T14:49:47.312900Z

I'm using the Material-UI packages from cljsjs and classical figwheel-main via leiningen. So not via yarn, so that might be why I've never run into a problem there.

v 2020-04-27T22:06:47.293700Z

It adds a lot of value if you are doing daily React development. But doesnt add any value in cljs land

v 2020-04-27T22:08:21.293900Z

You can use hooks in Reagent, this article explains clearly https://juxt.pro/blog/posts/react-hooks-raw.html

v 2020-04-27T22:10:33.294100Z

Also this is a an snippet from one of my projects. It uses MUI v4 and makeStyles hook.

(ns app.navigation
  (:require
   [reagent.core :as r]
   ["@material-ui/core" :refer [List ListItem Button]]
   ["@material-ui/styles" :refer [makeStyles]]
   ["@material-ui/icons" :refer [ExpandMore ExpandLess BarChart] :rename {ExpandMore ExpandMoreIcon
                                                                          ExpandLess ExpandLessIcon}]))

;;
(defn custom-styles [^js/Mui.Theme theme]
  #js {:root   #js {:margin-bottom (.spacing theme 3)}})

(def with-custom-styles (makeStyles custom-styles))

(defn navigation-item
  [{:keys [title icon label]}]
  [:> ListItem
   [:> Button
    [:> icon]
    title
    (when label
      [:> label])]])

;;
(def nav-list
  [{:title "Home" :href "/" :icon BarChart}
   {:title "Dashboard" :href "/dashboard" :icon BarChart}
   {:title "Projects" :href "/projects" :icon BarChart}
   {:title "Calendar" :href "/calendar" :icon BarChart}
   {:title "Clients" :href "/clients" :icon BarChart}
   {:title "Template Manager" :href "/templates" :icon BarChart}])

(defn navigation
  []
  (let [styles (with-custom-styles)]
    (r/as-element
     [:div {:class [(.-root styles)]}
      [:> List
       (for [nav nav-list]
         ^{:key (:title nav)}
         [navigation-item nav])]])))