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.
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).
@jrychter yes, provide and unique key
an unique key
Oh!
React can't reuse component if key is different
I used it myself once, to clear the form too :))
There you go! You saved me a fantastic amount of time, thanks.
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.
TFW you wrote a declarative forms library, and now you auto-generate data for it and use gensym
…
forms libraries, oh the joy
here are some of my previous approaches 😄 https://gist.github.com/martinklepsch/e1366008c5a478b33c00d324314da4fd
@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 🙂
And so far I'm pretty happy with the current one, not that it's ideal or anything.