Fork me on GitHub
#reagent
<
2024-02-14
>
andre10:02:55

hi, when i set functional components by default i have next error

andre10:02:16

so it seems like

(reagent/current-component)
(reagent/props current-component)
(reagent/children current-component)

andre10:02:24

not supported in functional components

andre10:02:30

is there a way to replace them ?

andre10:02:51

is there a way to get props and children in functional component?

andre10:02:49

yes

(defn get-props [^js/React.Component c]
  (let [p (.-props c)]
so it expects React.Component

p-himik10:02:37

When posting to the main channel, please combine your messages into a single post. You can use Shift-Enter to add a new line without sending a message and you can edit an already sent message to add some details. No need to do it now, just mentioning it for future reference.

👍 1
p-himik10:02:44

As for your actual question - those functions are usually used in lifecycle functions because it's the only direct way of retrieving that information from there. Except for current-component - usually you can just use (this-as this ...).

p-himik10:02:08

This begs the question - why do you need those in a function component? Why not just use the values directly that you have in that function?

andre10:02:34

so it seems like for functional components (set! (.-argv reagent-state) argv)

andre10:02:41

reagent-state`` is a component

andre10:02:32

so i can extract extract-props and extract-children from argv of current component

andre10:02:31

> This begs the question - why do you need those in a function component?

andre10:02:37

because props are optional

p-himik10:02:11

Personally, I find it much easier not to worry about all that by making props non-optional. :) Just pass an empty map. If you don't like that, you can just do what Reagent does - check if the first arg is a map.

1
andre10:02:14

i agree, props non-optional is better, but a lot of legacy code