Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

buildo-react-pure

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

buildo-react-pure

Light decorator that adds "shouldComponentUpdate" to pure react components to improve performance

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

react-pure

@pure is a light decorator that adds shouldComponentUpdate to pure react components to improve performance.

Install

npm i --save buildo-react-pure

Usage

@pure decorator can only be applied to React.Component(s) classes.

@pure
export default class MyComponent extends React.Component {

  render() {
    return <div />
  }

}

Under the hood

@pure adds the logic to the method shouldComponentUpdate to perform a shallow compare between current and previous props/state. If nor the props nor the state refs have changed, shouldComponentUpdate will return false and React will automatically use the result cached from previous render: you avoid a useless re-render!

@pure
export default class MyComponent extends React.Component {

  static propTypes = {
    input1: React.PropTypes.number.isRequired,
    input2: React.PropTypes.number.isRequired
  }

  render() {
    const { input1, input2 } = this.props;

    // some heavy computation
    const computedResult = heavyComputation(input1, input2);

    return (
      <div>
        {computedResult}
      </div>
    );
  }

}

In the example above if something triggers a re-render but input1 and input2 have still the same ref they had in the previous render the unnecessary heavyComputation will be completely avoid.

Keywords

FAQs

Package last updated on 03 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc