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.

addReducer helper causes components to re-render unnecessarily

See original GitHub issue

Hi,

Thank you for this great library, it really shorten the code.

I have noticed that my components using this.global render whenever global is updated, even if it updates something not used by this component. Is it normal ? I was expecting a behavior like React.PureComponent, the component just renders when the part of the state he uses get rendered, is it possible ?

Especially in my case, I have a component that uses a reducer function, it doesn’t use a value of the state. I am not on react 16.7 so I cannot use useGlobal.

PS: I am on react 16.6.

Thank you

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
CharlesStovercommented, Nov 21, 2018

Thank you for reporting this. I’ve pinpointed the bug, and I’ll deploy 0.1.1 sometime today to resolve it.

1reaction
CharlesStovercommented, Nov 21, 2018

Thanks for providing an example. What version of ReactN are you using? 0.0.9 or 0.1.0?

EDIT: This does look to be a bug with the addReducer helper.

You can see that it does not occur with the setGlobal method:

class Button extends React.Component {

  incrementX = () => {
    this.setGlobal(state => ({
      x: state.x + 1
    }));
  };

  render() {
    console.log('render button');
    return (
      <button onClick={this.incrementX}>
        increment
      </button>
    );
  }
}

I’ll look into getting this fixed for the addReducer helper as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optimizing React performance by preventing unnecessary re ...
This article explains how to update components only when necessary, and how to avoid common causes of unintentional re-renders. Use React.memo ...
Read more >
How to debug unnecessary rerenders in React | Bryce's Blog
Common reasons for rerendering: Hooks changing (ie useState 's setState methode being called) props changing (it will list the exact props!)
Read more >
Do Redux selectors cause unnecessary component renders?
Whether the component will re-render depends on what mapStateToProps returns. (Actually, it depends on the combined props object returned by ...
Read more >
Just Say No to Excessive Re-Rendering in React - GrapeCity
It is possible to accidentally create new props objects and force components to re-render unnecessarily. As we continue to delve deeper into ...
Read more >
5 Ways to Avoid React Component Re-Renderings
Memoization enables your code to re-render components only if there's a change in the props. With this technique, developers can avoid unnecessary ...
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