Fix a bug regarding the injected props #225
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While injecting props to the wrapped component, prioritize props that
come from the HOC state over props that are passed from the parent.
Not sure if this is a bug, or if my "fix" breaks something else, but here is the reason I needed this:
I'm doing server-side rendering; and in addition to decorating my components with React Refetch's
connect
for my client-side fetching needs; I also developed another HOC with a nearly same API calledwithInitialRequest
that is able to do fetching on the server side as well:What I need is the ability to override the content of that
brandsFetch
created bywithInitialRequest
using a lazy refresh method defined inconnect
:But this doesn't work, because the HOC returned from
connect
favors parent props over the props it generates from its state in case of a name collision while rendering the child component. SoSomeComponent
above can never get a "refreshed"brandsFetch
, as it is stuck with thebrandsFetch
coming from the upper HOC.The obvious workaround is this:
But this is boilerplate I'd rather not duplicate everywhere.
I think it generally makes sense that the props generated by the HOC itself should override the props coming from the parent and not the other way around. I feel that the inner wrapper should have priority in case of name collisions.
Looking forward to your thoughts.
Great library, btw.
: )