1
votes

I have a situation as follows. I have a class, say MyData.

I'd like to use this with React final form as follows:

<Form
  initialValues={myData} // instance of MyData
  render={({ values }) => /* values should be of type MyData */}
/>

Is this possible, without constructing an instance of MyData on every render? (That would not be ideal, as we're caching some expensive computations.)

1
I'm not sure what you are requesting. What do you mean by "should be of type MyData"? Are you using TS or Flow? The spread is causing you such "expensive calculations"? - Erik R.
You're right, I could've phrased that better. I ended up doing the following: gist.github.com/rbalicki2/b9b631c831c5870ffc26143fbeed1275 (Instead of using Form from react-final-form, I use this custom Form.) This works just fine for now, but I hadn't thought of this solution when posting this. Thank you! - Robert Balicki

1 Answers

0
votes

Looks to not be possible. In final form, we have the following line:

initialValues: initialValues && { ...initialValues },

and as far as I know, it is not possible to override the behavior of the spread operator in this way. This would require changes to final form.