areMergedPropsEqual doesn't seem to run
See original GitHub issueI have a connected component near the root of my app that looks like this
//render method for component
render(){
return this.props.children;
}
function mapStateToProps(state){
return {
state //used in some context methods that the component has which don't care about rendering
};
}
function areMergedPropsEqual(next, prev){
console.log('hi');
return next.children === prev.children;
}
export default connect(mapStateToProps, undefined, undefined, {areMergedPropsEqual})(Component);
i added the areMergedPropsEqual option because i was worried every redux change would trigger a rerender of the entire app unnecessarily.
The problem is that areMergedPropsEqual seems to be ignored. I put a breakpoint in there and it never gets hit. and there’s no console logs.
Is it possible that the option is being ignored?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:14 (5 by maintainers)
Top Results From Across the Web
React Redux connect(): When and how to use it
Cover when and how to use the React Redux connect() API to create container components that are connected to the Redux state.
Read more >How, When, and Why to Connect() in React JS - Medium
It provides its connected component with the pieces of the data it needs from the store, and the functions it can use to...
Read more >React/Redux export default connect() doesn't seem to be ...
Found out the issue... The import statement seems to play its role to the connection..
Read more >Container Component | ThinkBucket
Container provides a data "container" for presentational components which is only used to display the data (props look like blood). Qi9Owo.
Read more >Connect | React Redux
... and the functions it can use to dispatch actions to the store. It does not modify the component class passed to it;...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
areMergedPropsEqual
is never called if you use the default formergeProps
because the answer will always be false in that case. SincemergeProps
is only called ifstateProps
,dispatchProps
, orownProps
has changes, the defaultmergeProps
will always produce an object that has different values. Avoiding that extra shallow compare is a significant perf boost.Should probably update the API docs to clarify this.
I’m seeing a case where ownProps are certainly changing, stateProps are not referenceEqual, but areMergedPropsEqual still does not run.
It seems from some quick testing that passing null or undefined as mergeProps causes areMergedPropsEqual not to run. Replacing the falsy mergeProps value with the default implementation
function defaultMergeProps(stateProps, dispatchProps, ownProps) { return { …ownProps, …stateProps, …dispatchProps } }
seems to cause areMergedPropsEqual to run as expected and described in @jimbolla 's comment.