Connect doesn't warn if same property is sent from both parent and state
The default merge method in connect:
const defaultMergeProps = (stateProps, dispatchProps, parentProps) => ({
...parentProps,
...stateProps,
...dispatchProps
})
Will just overwrite existing parent props with state props when same key is used.
IMHO it'd be better to show a warning to console, saving developers debugging time & effort
Not sure I agree with this, as that's the whole point of the mergeProps function: It lets you customize this default behavior (almost always for this exactly kind of problem).
I mostly agree, but given that it would be a dev-only check, I'm not sure it's actually a bad idea. Or rather, it seems like a decent idea, and I don't see any particular downside to it.
BTW, since this is dev-only, I'll revert my previous comment and say this is an OK idea. 😄
Are there any valid use cases where a developer wants it to just overwrite and not complain? In that case, the developer has to do one of:
- Live with the warning in dev mode.
- Implement their own
mergePropsthat doesn't warn, butconnect()contains an optimization whenmergePropsis omitted, avoiding an extra shallow equality check. This means their app will run slightly slower. It's probably unnoticeable except for edge cases involving a high frequency of dispatches that result in that component'smapStateToPropsproducing new results, or that component receiving new props from parent at a high frequency. - If they do hit that edge case for performance, then replace that particular usage of
connectwithconnectAdvancedand be responsible for their of memoization of props.
I'm OK with all that, but now we probably need to document this, probably in some advanced optimization section.
Closing after merged PR #508