reagent

andre 2024-02-14T10:02:55.380149Z

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

andre 2024-02-14T10:03:16.981739Z

so it seems like

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

andre 2024-02-14T10:03:24.593059Z

not supported in functional components

andre 2024-02-14T10:03:30.472689Z

is there a way to replace them ?

andre 2024-02-14T10:03:51.239599Z

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

andre 2024-02-14T10:05:49.126619Z

yes

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

p-himik 2024-02-14T10:09:37.815499Z

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-himik 2024-02-14T10:11:44.972419Z

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-himik 2024-02-14T10:12:08.306359Z

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?

andre 2024-02-14T10:12:34.679179Z

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

andre 2024-02-14T10:12:41.763709Z

reagent-state`` is a component

andre 2024-02-14T10:13:32.344979Z

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

andre 2024-02-14T10:13:33.254879Z

ok

andre 2024-02-14T10:13:35.095149Z

thanks

andre 2024-02-14T10:14:31.189129Z

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

andre 2024-02-14T10:14:37.572599Z

because props are optional

p-himik 2024-02-14T10:18:11.004689Z

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
andre 2024-02-14T10:20:14.232599Z

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