dvdzkwsk / react-reformed

Make React forms simple again, see it here:
https://react-reformed.zuko.me/
MIT License
541 stars 32 forks source link

[initialModel] if redux updates initialModel, update model in FormWra… #9

Closed branweb1 closed 7 years ago

branweb1 commented 7 years ago

The library currently does not work well with react-redux's connect component for defining an initialModel.

Oftentimes store data is update asynchronously (e.g. make an api call when a component mounts and putting the result in the store). connect passes these asynchronous changes to this library's FormWrapper as props, but these changes are not reflected in initialModel data since FormWrapper only uses it in its constructor, which is not called on prop change.

This PR modifies FormWrapper to update its state if initialModel changes. Now if any initialModel values are not resolved when the component mounts, these values are still displayed.

dvdzkwsk commented 7 years ago

Thanks for the PR, I realize that this has sat unnoticed for over a year, so I sincerely apologize for that. I'm definitely a fan of your idea, and have encountered the use case myself, but think it would be better to treat the model as immutable, as things in React generally are. That way, your check just becomes this.props.initialModel !== nextProps.initialModel, which benefits us in terms of speed (i.e. much quicker check on every new set of props) and simplicity (i.e. there's no confusion about it not being a deep equality check).

In the spirit of getting this merged, I'll just branch off of your branch to make the additional commit. Thank you for suggesting this feature!