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

style-equal

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

style-equal

An efficient equality algorithm for React Native inline styles

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.7K
decreased by-7.52%
Maintainers
1
Weekly downloads
 
Created
Source

style-equal

An efficient equality algorithm for React Native inline styles

Why

shouldComponentUpdate is a powerful way to improve performance of react and react native applications, but often you will want to allow for a component to have a style prop to make the style of something be configurable.

Since style in react native can be of many forms (an object, a number, an array of both, or a nested array of both), it is not trivial or practical to implement an equality test for these props in the shouldComponentUpdate method.

Installation

npm i style-equal --save

Usage

import styleEqual from 'style-equal';

// ...

shouldComponentUpdate(nextProps) {
  return !styleEqual(this.props.style, nextProps.style);
}

Caveats

The styleEqual algorithm is implemented to be fast and efficient for usage with shouldComponentUpdate methods in react. The algorithm will never give a false-positive (ie, saying two things are equal when they are not), however, there are things that are semantically equivalent that the algorithm will return false for. One example of this is when comparing two styles such as:

styleEqual([1, false, 2], [1, 2]) // returns false

The above will always render the same styles, however the algorithm is built to assume that the position of a style will not change "slots" of the array.

Keywords

FAQs

Package last updated on 24 Apr 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