Fork me on GitHub
#reagent
<
2020-04-29
>
donavan14:04:06

Is there a way to easily add the :key metadata to form-3 components. I need to completely recreate a form-3 component which I can do by…

[:div ^{:key changing-thing} [form-3-component changing-thing]]
…but I’d prefer it if it were encapsulated within the component. Or is there another way of doing this that I’m not thinking about?

lilactown14:04:11

keys are not encapsulated within components

donavan14:04:23

ok, that makes sense, I know it’s react that is recreating the component from scratch when the key changes… is there another way of achieving a complete component recreation?

donavan14:04:10

besides a simple wrapping component that is

donavan14:04:57

(defn wrapper [changing-thing]
  ^{:key changing-thing} [form-3-component changing-thing])

lilactown15:04:11

React components don't have control over when they mount/unmount

donavan15:04:27

good point

lilactown15:04:32

you can have the key be part of the usage of the component, use the wrapper method, or refactor the component so that it doesn't rely on component instantiation when props change

lilactown15:04:12

it would be interesting if components could unmount themselves, but it's not possible with react today AFAIK

donavan15:04:35

Yeah, I think you’re right… things work well with the component as is so I reckon I’ll just use the wrapper. Thanks!

v17:04:57

How do you test reagent view functions. I tried looking online didnt find any good resources

v18:04:28

@UBK8J929J just tried devcards. And I have to say I am very impressed!

juhoteperi19:04:49

Cljs podcast episode about Reagent is out! https://soundcloud.com/user-959992602/s4-e2-reagent-with-juho-teperi (this was recorded half a year ago so it doesn't go into detail of the latest changes, but Hooks are mentioned)

👂 2
parrot 4
👍 2