reagent 2024-02-14

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

so it seems like

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

not supported in functional components

is there a way to replace them ?

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

yes

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

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

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

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?

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

reagent-state`` is a component

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

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

because props are optional

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

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