Fork me on GitHub
#clojurescript
<
2018-06-22
>
roti11:06:49

is there a way to render static html code with react (which resides in a html file)?

lilactown16:06:14

you can render React to a string

Alex12:06:25

check out https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml, and pay particular attention to the dangerously bit. There is probably a way that you can achieve your goal that doesn't involve inlining HTML, and that way will not expose you to the problems that inlining HTML from a stream will.

Alex13:06:42

@roti It sounds like you're using a static file from your question, and you're asking in clojurescript so you already have a build step. I strongly encourage you to check out kioo (https://github.com/ckirkendall/kioo) which lets you slurp up the contents of an HTML file as a template and returns a react virtual dom.

djtango15:06:47

Hey folks, sorry if this is a repeat but is it common knowledge that cljsbuild will clobber variables in a let scope if they have variables of the same name but one is snake case and one is kebab case?

djtango15:06:36

e.g.

(let [foo-bar 1, foo_bar 2]
  (println foo-bar)
  (println foo_bar))
;;=> 2
;;=> 2

pesterhazy15:06:02

it's unavoidable

djtango15:06:07

I couldn't find any reference to this on a cursory google

pesterhazy15:06:30

given ClojureScript's symbol mangling rules

pesterhazy15:06:53

I'm not sure it's documented anywhere

pesterhazy15:06:33

maybe it would be possible to add a warning

pesterhazy15:06:14

the tricky bit is that shadowing with the same name is often desired behavior

djtango15:06:30

how come figwheel is able to get it right?

djtango15:06:48

as in - what is different between how they are compiled?

pesterhazy15:06:45

are you sure there's a difference?

djtango15:06:34

I stuck an equivalent print statement in a figwheel project and it didn't clobber the variables

pesterhazy15:06:45

Interesting difference:

(defn aaa []
  (let [foo-bar 1, foo_bar 2]
    (println "aaa" foo-bar)
    (println "bbb" foo_bar)))

(let [foo-bar 1, foo_bar 2]
  (println "AAA" foo-bar)
  (println "BBB" foo_bar))
(aaa)

pesterhazy15:06:12

AAA 1
BBB 2
aaa 2
bbb 2

pesterhazy15:06:35

When run from Figwheel, the shadowing happens only inside the function body, not in the top-level let

pesterhazy15:06:31

In any case, ignore my "avoidable" comment above 🙂

dnolen18:06:22

@djtango @pesterhazy it’s probably avoidable, but also I pretty minor issue

dnolen18:06:51

since it’s pretty unusual to mix naming conventions, snake case is not idiomatic

djtango21:06:50

thanks for getting back to me! Agreed it's not idiomatic - I came across it when destructuring a snake-cased and processing it in-flight so it was somewhat indicative that the function was doing to much...