question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

areMergedPropsEqual doesn't seem to run

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
jimbollacommented, Mar 13, 2017

areMergedPropsEqual is never called if you use the default for mergeProps because the answer will always be false in that case. Since mergeProps is only called if stateProps, dispatchProps, or ownProps has changes, the default mergeProps 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.

0reactions
TomMahlecommented, Sep 5, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found