reagent

A minimalistic ClojureScript interface to React.js http://reagent-project.github.io/
wimomisterx 2020-03-22T11:20:45.208600Z

Hi, is this the recommended way of rendering a minutes since component?

(defn mins-since [start-time]
  (let [mins (r/atom (mins start-time))]
    (fn [start-time]
      (js/setTimeout #(swap! mins inc) 60000)
      [:span @mins])))

p-himik 2020-03-22T11:53:42.208700Z

IIRC the render function may potentially be called multiple times, so I wouldn't do it like that. Reagent has a very similar example right on its landing page: https://reagent-project.github.io/

p-himik 2020-03-22T11:53:57.208900Z

Search for the words "Hello world, it is now".

wimomisterx 2020-03-22T12:48:53.209100Z

Thought so, is with-let a better use here?

p-himik 2020-03-22T12:53:50.209300Z

If you really want to avoid having a global counter, then I think you need to create a proper class component, use setInterval, and dispose of that interval once the component is unmounted.

juhoteperi 2020-03-22T14:31:08.210700Z

Instead of yourself counting the minutes, trigger update every x seconds, and calculate difference between start and end timestamps.

juhoteperi 2020-03-22T14:33:12.211100Z

https://github.com/metosin/komponentit/blob/master/src/cljs/komponentit/timeago.cljs#L49 this is maybe unnecessarily too complex, but might give some idea. with-let is probably good way to create and destry interval.

juhoteperi 2020-03-22T14:34:37.211500Z

(It uses timeout instead of interval to optimize how often it is called, based on the previous difference.)

juhoteperi 2020-03-22T14:55:43.216300Z

I got test coverage reports working with Cljs tests: https://github.com/reagent-project/reagent/pull/484 🎉

👏 1
wimomisterx 2020-03-22T15:33:50.216900Z

I agree, that's a better approach. Thanks

2020-03-22T19:05:32.219200Z

How should I translate startAdornment in the following React code into Reagent?

<TextField
        className={classes.margin}
        id="input-with-icon-textfield"
        label="TextField"
        InputProps={{
          startAdornment: (
            <InputAdornment position="start">
              <AccountCircle />
            </InputAdornment>
          ),
        }}
      />

2020-03-22T19:08:23.220500Z

I was trying to have to have something like

[:> TextField {:input-props {:startAdornment (r/create-element InputAdornment #js {:position "start"} "Test")}}]
But I am not getting anything rendered.

2020-03-22T19:11:01.221Z

Also the following does not work

(r/as-element [:> InputAdornment {:position "start"} "Test"])

2020-03-22T19:11:43.221400Z

From API documentation, startAdornment should be a node: https://material-ui.com/api/input/

p-himik 2020-03-22T19:17:09.221600Z

inputProps != InputProps. Stupid naming IMO, given that inputProps are actually attributes. :input-props is translated into inputProps. And you need :InputProps.

2020-03-22T19:20:09.221800Z

Ya, thx.

2020-03-22T19:37:10.222Z

I was confused since read-only property was working with both inputProps and InputProps, so I didn't consider that there is a problem with this.