Fork me on GitHub
#clojurescript
<
2023-09-19
>
keychera03:09:03

I am currently trying to convert my old react toy project to clojurescript and I found this js import statement

import { Row, Col, Avatar, Typography, Card, Tag, Tabs } from 'antd' 
  
  const { Text } = Typography
  const { Meta } = Card
which I am stumped on how to convert the const { Text } = Typography part, but after some trial and error, I found that I can do this
(ns something
  (:require ["antd" :refer [Row, Col, Avatar, Typography, Card, Tag, Tabs]]))

(def Text Typography.Text)
(def Meta Card.Meta)
is this how you do it? I haven’t managed to find anything regarding this (and I lack keyword to describe that js syntax)

Bobbi Towers03:09:04

If you had a lot of nested objects to deal with, the applied-science/js-interop library supports destructuring of js objects

keychera03:09:13

I have tried applied-science as well, but not in the context of destructuring import like this, I’ll take a look

thheller06:09:46

the proper way to write (def Text Typography.Text) is (def Text (.-Text Typography)) but the dot syntax is convenient and works too

💡 2
Nasiru Ibrahim17:09:40

Your syntax is OK.

1