Fork me on GitHub
#clojurescript
<
2022-11-06
>
M J09:11:24

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. Thanks

p-himik09:11:36

That'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.

M J09:11:26

Ok I got it.. thnx

Felipe Nascimento20:11:23

Hi, I'm facing some difficulty to be able to use a nested function of a component

Felipe Nascimento20:11:50

<ActionIcon variant="default" onClick={() => toggleColorScheme()} size={30}>
              {colorScheme === 'dark' ? <IconSun size={16} /> : <IconMoonStars size={16} />}
</ActionIcon>

Felipe Nascimento20:11:56

I need convert this to cljs

Felipe Nascimento20:11:15

but the toggleColorScheme() come from const { colorScheme, toggleColorScheme } = useMantineColorScheme();

Felipe Nascimento20:11:34

idk how to call from the onClick event

Felipe Nascimento20:11:26

I tried this

:on-click (fn [t]
  (. mantine.core/useMantineColorScheme -toggleColorScheme))}]

p-himik20:11:46

(let [^js color-scheme-obj (useMangineColorScheme)
      toggle-color-scheme (.-toggleColorScheme color-scheme-obj)]
  [:> ActionIcon {:variant  "default"
                  :on-click (fn []
                              (toggle-color-scheme))}
    ...])

kennytilton20:11:23

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?

1
p-himik20:11:18

Why? The JS code doesn't do it. It's a function that's already assigned to a field.

👍 1
Felipe Nascimento20:11:49

sometimes the jump difficulty from clojure to clojurescript/react is unbelievable

p-himik20:11:04

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 :>).

Felipe Nascimento20:11:19

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?

p-himik20:11:57

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.

p-himik20:11:18

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.

👍 1
Felipe Nascimento22:11:33

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

Felipe Nascimento22:11:48

(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))}]))}]

Felipe Nascimento23:11:19

@U2FRKM4TW I did as you show me, but now Im facing some hook error ^

p-himik06:11:07

Have you tried looking that error up online?

Felipe Nascimento10:11:25

yes, I tried place inside [:f>

p-himik10:11:43

Why did you put the hook inside the on-click handler? IIRC the JS version didn't do it.

Felipe Nascimento10:11:23

I just simplify to this

Felipe Nascimento10:11:03

`

(let [^js x (mantine.core/useMantineColorScheme)
      x1 (.-toggleColorScheme x)]
  (js/console.log x)
  (js/console.log x1))
`

p-himik10:11:15

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.

Felipe Nascimento10:11:54

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

Felipe Nascimento10:11:17

but in the original code, the toggleColorScheme is used inside on-click

p-himik10:11:19

toogleColorScheme is probably a plain function. But useMantineColorScheme is probably a hook.

p-himik10:11:35

Well, as you can see in the code at that link, Demo is a function component and that hook is used right at its start. You just gotta replicate that.