Fork me on GitHub
#clojurescript
<
2021-08-07
>
Richard Bowen02:08:29

Hey, are these snippets equivalient? ClojureScript

(defn tab-panel [{:keys [children value index & other]}]
   [:div (merge {:role "tabpanel"
                 :hidden (not= value index)
                 :id (str "simple-tabpanel-" index)} other)
         (if (= value index)
          [box {:py 3} children])])
JavaScript
function TabPanel(props) {
  const { children, value, index, ...other } = props;

  return (
    <div
      role="tabpanel"
      hidden={value !== index}
      id={`simple-tabpanel-${index}`}
      {...other}
    >
      {value === index && (
        <Box py={3}>
          {children}
        </Box>
      )}
    </div>
  );
}

indy04:08:50

{:keys [children value index & other]}
What you're intending with & other is incorrect. You'd want,
{:keys [children value index] :as props}
and then use the props.

indy04:08:30

There is no way in CLJ(S) to do the ...other bit here,

const { children, value, index, ...other } = props;
You will have to think differently, like dissocing children, value and index from the props in the suggestion above.

indy04:08:28

(let [{:keys [a b & o]} {:a 1 :b 2 :& 3 :o 4}]
   [a b & o])
=> [1 2 3 4]

indy04:08:40

^ to illustrate why {:keys [children value index & other]} doesn't work as you intended.

quoll14:08:44

Incidentally, that’s react JS, and not JS 🙂

quoll14:08:09

I got confused for a second before I woke up 🙂

borkdude13:08:28

Can anyone find out why this test isn't running? (you can watch tests with bb watch-tests or by executing the corresponding command from bb.edn manually) https://github.com/borkdude/nbb/blob/df0edd3c2a560ea3954dc6943a228c3d49668e75/test/nbb/main_test.cljs#L25

borkdude13:08:34

aaah: > NOTE: You cannot have more than one async test per deftest form or only the first one will run.