Fork me on GitHub
#rum
<
2017-07-16
>
jrychter11:07:19

In the render fn, is there a way to force a child component to be re-created from scratch? E.g. if one of my args changes, I don't want to just pass the changed arg down the tree, because I know the child will not be able to deal with the change. I want to destroy the child and re-create it.

jrychter11:07:56

And yes, I know this is not the expected way to use React. I hit a corner case (complex forms where the number of fields can change).

Niki11:07:18

@jrychter yes, provide and unique key

Niki11:07:36

an unique key

Niki11:07:56

React can't reuse component if key is different

Niki11:07:15

I used it myself once, to clear the form too :))

jrychter11:07:30

There you go! You saved me a fantastic amount of time, thanks.

jrychter11:07:17

My forms library (rather extensive by now) assumes that the form manages tons of local state. I don't see a way to reconcile this with the number of fields changing. It's easier to just recreate the form in that case.

jrychter11:07:45

TFW you wrote a declarative forms library, and now you auto-generate data for it and use gensym

martinklepsch13:07:38

forms libraries, oh the joy

jrychter22:07:57

@martinklepsch after about, oh, 12 years or so of thinking about the problem (and after having built at least five) I feel slightly more qualified as far as forms libraries are concerned 🙂

jrychter22:07:53

And so far I'm pretty happy with the current one, not that it's ideal or anything.