This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-06
Channels
- # announcements (3)
- # babashka (1)
- # beginners (26)
- # calva (1)
- # cider (17)
- # clj-commons (16)
- # clj-kondo (11)
- # clojure (21)
- # clojure-europe (9)
- # clojure-norway (1)
- # clojure-portugal (2)
- # clojure-spec (8)
- # clojure-uk (4)
- # clojurescript (35)
- # datomic (5)
- # emacs (9)
- # figwheel-main (15)
- # fulcro (26)
- # honeysql (1)
- # lsp (5)
- # off-topic (2)
- # polylith (1)
- # rdf (6)
- # re-frame (4)
- # reagent (15)
- # reitit (9)
- # releases (2)
- # shadow-cljs (4)
- # sql (25)
- # squint (2)
- # xtdb (7)
Hi, I wanted to know how do I write this in clojurescript (styles):
td {
border: solid 1px #000;
border-style: none solid solid none;
padding: 10px;
}
tr:first-child td:first-child { border-top-left-radius: 10px; }
tr:first-child td:last-child { border-top-right-radius: 10px; }
I mainly want to know how do I target "first-child" in clojurescript. ThanksThat's CSS which does not exist in ClojureScript by itself. It all depends on what exactly you're using for CSS-in-CLJS, if anything.
Hi, I'm facing some difficulty to be able to use a nested function of a component
<ActionIcon variant="default" onClick={() => toggleColorScheme()} size={30}>
{colorScheme === 'dark' ? <IconSun size={16} /> : <IconMoonStars size={16} />}
</ActionIcon>
I need convert this to cljs
but the toggleColorScheme()
come from const { colorScheme, toggleColorScheme } = useMantineColorScheme();
idk how to call from the onClick event
I tried this
:on-click (fn [t]
(. mantine.core/useMantineColorScheme -toggleColorScheme))}]
(let [^js color-scheme-obj (useMangineColorScheme)
toggle-color-scheme (.-toggleColorScheme color-scheme-obj)]
[:> ActionIcon {:variant "default"
:on-click (fn []
(toggle-color-scheme))}
...])
ty I will try!
Should the let binding toggle-color-scheme (.-toggleColorScheme color-scheme-obj)
have an octothorpe to make it a function? toggle-color-scheme #(.-toggleColorScheme color-scheme-obj)
, @U2FRKM4TW?
Why? The JS code doesn't do it. It's a function that's already assigned to a field.
original link
sometimes the jump difficulty from clojure to clojurescript/react is unbelievable
I'd be curious to know what you struggled with here exactly (see my response to your previous message and how it's just JS interop along with some Reagent-specific thing, namely :>
).
it was just a rant ;), can you point me to some material to better understand how to interpolate and build a react app in clojurescript application?
Sorry, I don't keep track of such materials. But some primers on CLJS<->JS interop, without any React, are easy to find and are very useful.
Also, you need to unpack what's going on in JS before writing it in CLJS - at least, before you get fully comfortable with interop. E.g. here
const { colorScheme, toggleColorScheme } = useMantineColorScheme();
there are 3 things going on:
1. Calling the useMantineColorScheme
2. Extracting the colorScheme
field of the returned object and assigning it to a constant with the same name
3. Same but for toggleColorScheme
Then, you gotta apply interop step by step:
1. This would be (useMantineColorScheme)
2. This one you don't need at all
3. This one would be (.-toggleColorScheme that-obj-from-before)
And so on, and so forth.react-dom.development.js:14907 Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons
(require '["@mantine/core" :as mantine.core])
[:> mantine.core/ActionIcon {:variant "default"
:size 30
:on-click (fn [x]
(let [^js color-scheme-obj (mantine.core/useMantineColorScheme)
toggle-color-scheme (.-toggleColorScheme color-scheme-obj)]
[:> action-icon {:variant "default"
:on-click (fn []
(toggle-color-scheme))}]))}]
@U2FRKM4TW I did as you show me, but now Im facing some hook
error ^
yes, I tried place inside [:f>
and r/as-element
Why did you put the hook inside the on-click
handler? IIRC the JS version didn't do it.
I just simplify to this
`
(let [^js x (mantine.core/useMantineColorScheme)
x1 (.-toggleColorScheme x)]
(js/console.log x)
(js/console.log x1))
`Hooks are special. You can't just use them as you please, even if it makes the code appear simpler. You have to use them in a way they are designed to be used.
I only need from const { colorScheme, toggleColorScheme } = useMantineColorScheme();
the toggleColorScheme
function, but seans that the toogleColorSchema is a hook so I can`t use it or even access it
but in the original code, the toggleColorScheme
is used inside on-click
toogleColorScheme
is probably a plain function. But useMantineColorScheme
is probably a hook.
for sure it is