Closed branweb1 closed 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!
The library currently does not work well with react-redux's
connect
component for defining aninitialModel
.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'sFormWrapper
as props, but these changes are not reflected ininitialModel
data sinceFormWrapper
only uses it in itsconstructor,
which is not called on prop change.This PR modifies
FormWrapper
to update its state ifinitialModel
changes. Now if anyinitialModel
values are not resolved when the component mounts, these values are still displayed.