npmclojurescriptclojurescript-javascript-interopshadow-cljs

Using the resulting object from require call in ClojureScript?


In JavaScript there is the idiom:

const ScrollTrigger = require('ScrollTrigger-classes');

var trigger = new ScrollTrigger({
		once: true
	});

How do I do the same thing in ClojureScript using Shadow-CLJS for npm modules?


Solution

  • Preferably you do this via the ns.

    (ns your.thing
      (:require ["ScrollTrigger-classes" :as ScrollTrigger]))
    
    (let [trigger (ScrollTrigger. #js {:once true})]
      ...)
    

    If you must you can just use (let [ScrollTrigger (js/require "...") ...] ...).