Fork me on GitHub
#clojurescript
<
2023-02-23
>
ccann23:02:44

I’m trying to use @date-io/moment package with material UI v4 time picker.

(ns cljs-material-ui.core
  (:require [react :as React]
            ["@material-ui/core" :as MaterialUI]
            ["@material-ui/pickers" :as MUIPickers]
            ["@date-io/moment" :as DateIOMoment]))

(def moment-utils (aget DateIOMoment "MomentUtils"))
but moment-utils is always nil . I need to pass it as MuiPickersUtilsProvider component utils prop as per https://stackoverflow.com/a/59954779

ccann23:02:21

essentially I need to translate

import MomentUtils from "@date-io/moment";
<MuiPickersUtilsProvider utils={MomentUtils}>
into cljs

hifumi12303:02:59

Are you using a CJS or ESM distribution? I'll assume ESM for now, which in case you'll need to (require '["@date-io/moment$default" :as MomentUtils]) Assuming the utils prop accepts a function, then you should be able to use MomentUtils directly

p-himik06:02:28

Also, don't use aget with strings - it's intended only for arrays. When you need to get a field from a JS object that didn't come from goog.*, just use externs inference and interop: (.-someField ^js obj) (and ^js is not even necessary a lot of the times).

thheller07:02:50

(def moment-utils DateIOMoment/MomentUtils) is also preferred over aget. .- also works of course

thheller07:02:36

or ["@date-io/moment$default.MomentUtils" :as moment-utils] as the shortest variant, just directly in require without any def