How to use Material UI in ClojureScript?
With shadow-cljs and Reagent this is piece of cake:
- Start new project e.g.
lein new reagent-frontend <myproject>
- Install MUI:
npm install @mui/material @emotion/react @emotion/styled
- Now let's run the server with hot reloading:
Next actions will be innpm install npx shadow-cljs watch app
core.cljs
file: - Add import:
We will use Material UI's button as an example - other components work the same way.(ns myproject.core (:require [reagent.core :as r] [reagent.dom :as d] ["@mui/material" :as mui])) ; <---
- Define our button component (wrapper):
if you want to learn more about(defn text-button [label] [:> mui/Button {:variant "text"} label]) ; <--- here we use MUI component
:>
and react interop read this. - add our new component to
home-page
which is our main component/container:(defn home-page [] [:div [:h2 "Welcome to Reagent"] [text-button "Click me!"]])
- The End!
If you find this tutorial interesting, check my newest Clojure and ClojureScript course! - Clojure Hacker.
ย