How can I use Clojurescript to interact with the html DOM?

I am new to Clojurescript. I want to know how to create html elements and how to change their properties using clojurescript. I can't seem to find a lot of relevant information on the Internet.

+4
source share
2 answers

Take a look at the Reagent project, which "provides a minimalistic interface between ClojureScript and React."

The Reagent project website includes this example:

(ns example
  (:require [reagent.core :as r]))

(defn simple-component []
  [:div
   [:p "I am a component!"]
   [:p.someclass
    "I have " [:strong "bold"]
    [:span {:style {:color "red"}} " and red "] "text."]])

(defn render-simple []
  (r/render [simple-component]
    (.-body js/document)))

simple-component DOM body node of js/document. Reagent - , HTML, .

HTML DOM ClojureScript, , Reagent ClojureScript; .

+4

ClojureScript JavaScript . JavaScript- DOM, :

(-> js/document
    (.getElementById "app")
    (.-innerHTML)) ; returns contents of element with id 'app'

(-> js/document
    (.getElementById "app")
    (.-innerHTML)
    (set! "Hello Clojure!")) ; Sets new content for element

ClojureScript cheatsheet JavaScript CLJS.

- DOM. @scott-lowe answer , ClojureScript React ( ) JS . -.

, re-frame, . - Leiningen build tool lein new re-frame my-app-name. , . lein figwheel, cljs . view.cljs, hiccup-like .

+4

Source: https://habr.com/ru/post/1681926/


All Articles