New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

configure-should-component-update

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

configure-should-component-update

Provides a function to configure React's shouldComponentUpdate() function in a declarative way

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
increased by25%
Maintainers
1
Weekly downloads
 
Created
Source

configure-should-component-update

npm version License: MIT Build Status Coverage Status

Provides a function to build a customized React's shouldComponentUpdate() function in a declarative way.

Example

  import React from 'react';
  import {configureShouldComponentUpdate} from 'configure-should-component-update';

  class Label extends React.Component {
    static propTypes = {
      text: PropTypes.string,
      color: PropTypes.any,
    };

    render() {
      // ...
    }
  }

  configureShouldComponentUpdate(Label, {
    props: {
      text: (prev, next, { key, props, state, nextProps, nextState }) => a == b,
    },
    state(prevState, nextState, { props, nextProps }) {
      return prevState.pressed === nextState.pressed && !nextProps.disabled;
    }
  });

Here configureShouldComponentUpdate function call will create a function in Label.prototype.shouldComponentUpdate, which will be shallowly comparing this.props with nextProps and this.state with nextState, but in addition to it, the preconfigured properties like text will use the corresponding equality comparers you provide.

Hence, in our example, if <Label> is rendered with text="3" and then, with text={3}, we are not going to have an extra re-render.

TODO

More documentation is to follow.

License

Licensed under MIT License.

Keywords

FAQs

Package last updated on 18 Mar 2019

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