Necrotizing Pineapple Music

    shallow-equal-props
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.2 • Public • Published

    shallow-equal-props Build Status

    Shallow Equal for React's props.

    It is a customize version of shallow-equal-object.

    Features

    • Shallow equal for objects
    • Support React.Element
      • Check equality React.Element if props include React.Element like children,

    Install

    Install with npm:

    npm install shallow-equal-props
    

    Usage

    Shallow equal for props.

    import { shallowEqualProps } from "shallow-equal-props";
    import * as React from "react";
    class MyComponent extends React.Component {
        shouldComponentUpdate(nextProps){
            return !shallowEqualProps(this.props, nextProps);
        }
    }

    Support React.Element

    // equal to React.Element
    // Check: key and type
    const elementA = React.createElement("div", { key: "a" });
    const elementB = React.createElement("div", { key: "a" });
    assert.equal(shallowEqualProps({
        child: elementA
    }, {
        child: elementB
    }), true, "should be equal");
    // Not equal: type
    const elementA = React.createElement("div", { key: "a" });
    const elementB = React.createElement("span", { key: "a" });
    assert.equal(shallowEqualProps({
        child: elementA
    }, {
        child: elementB
    }), false, "element is not same type");
    // Not equal: key
    const elementA = React.createElement("div", { key: "a" });
    const elementB = React.createElement("div", { key: "b" });
    assert.equal(shallowEqualProps({
        child: elementA
    }, {
        child: elementB
    }), false, "elementA is not equal elementB");

    Changelog

    See Releases page.

    Running tests

    Install devDependencies and Run npm test:

    npm i -d && npm test
    

    Contributing

    Pull requests and stars are always welcome.

    For bugs and feature requests, please create an issue.

    1. Fork it!
    2. Create your feature branch: git checkout -b my-new-feature
    3. Commit your changes: git commit -am 'Add some feature'
    4. Push to the branch: git push origin my-new-feature
    5. Submit a pull request :D

    Author

    License

    MIT © azu

    Install

    npm i shallow-equal-props

    DownloadsWeekly Downloads

    515

    Version

    1.0.2

    License

    MIT

    Last publish

    Collaborators

    • azu