robinweser/react-controlled-form

data field is returned undefined in the Form renderProps despite being initialized with the initialFields form props

JZBo opened this issue · 3 comments

JZBo commented

Greetings! It's me again, please don't hate me too much :).

I discovered a somewhat weird behaviour that I think merits to be reported.
I found out that in a Form whose default field values are initialized through the initialFields props, the { data } property of its render props is undefined at first, even if the INIT_FORM action of RCF is called correctly with its proper payload, including the default form values.
It's only after all the INIT_FIELD actions are dispatched that the form is re-rendered with the expected data values in its render props.

I'll attach an image of the chrome console to better illustrate what I meant. (I put a console.log for the renderProps at the beginning of the Form render function)

2018-02-14_11-07-07_1

I discovered this when migrating some components that where enhanced with the old 'withData' HoC of the previous version, (resulting in a crash due to properties being unexpectedly undefined). So, for what it's worth, it seems to be a behaviour that wasn't present in the previous version of RCF.

It's not really a very serious bug, since it's easy to pass the very same default values used for initialization in the initialFields of the form as a backup if data is found to be undefined, but it seems a quirk resulting in something that's not really supposed to work this way.

Seems like an actual issue, no idea why it would have worked before... But I'll fix it with the next release. Thanks for all your patience and effort testing and fixing docs and bugs with the new release - I really appreciate that!

JZBo commented

Glad you're not too upset :).
I really like your modules, and I personally find RCF the best and clearest lightweight form handling library for react-redux, so I was perhaps a bit overeager to try the new version.

This should've been fixed with the latest release, right?