How to use enzyme-shallow-equal - 4 common examples

To help you get started, we’ve selected a few enzyme-shallow-equal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github airbnb / enzyme / packages / enzyme / src / ShallowWrapper.js View on Github external
)
              ) {
                instance.componentDidUpdate(prevProps, state, snapshot);
              }
            } else if (
              lifecycles.componentDidUpdate
              && typeof instance.componentDidUpdate === 'function'
            ) {
              if (lifecycles.componentDidUpdate.prevContext) {
                instance.componentDidUpdate(prevProps, state, prevContext);
              } else if (!state || shallowEqual(this.instance().state, state)) {
                instance.componentDidUpdate(prevProps, state);
              }
            }
          // If it doesn't need to rerender, update only its props.
          } else if (!shallowEqual(props, instance.props)) {
            instance.props = (Object.freeze || Object)({ ...instance.props, ...props });
          }
          this.update();
        });
      });
github airbnb / enzyme / packages / enzyme / src / ShallowWrapper.js View on Github external
shouldRender
            && !this[OPTIONS].disableLifecycleMethods
            && instance
          ) {
            privateSetChildContext(adapter, this, instance, node, getChildContextSpy);
            if (lifecycles.getSnapshotBeforeUpdate) {
              let snapshot;
              if (typeof instance.getSnapshotBeforeUpdate === 'function') {
                snapshot = instance.getSnapshotBeforeUpdate(prevProps, state);
              }
              if (
                lifecycles.componentDidUpdate
                && typeof instance.componentDidUpdate === 'function'
                && (
                  !state
                  || shallowEqual(state, this.instance().state)
                  || typeof type.getDerivedStateFromProps === 'function'
                )
              ) {
                instance.componentDidUpdate(prevProps, state, snapshot);
              }
            } else if (
              lifecycles.componentDidUpdate
              && typeof instance.componentDidUpdate === 'function'
            ) {
              if (lifecycles.componentDidUpdate.prevContext) {
                instance.componentDidUpdate(prevProps, state, prevContext);
              } else if (!state || shallowEqual(this.instance().state, state)) {
                instance.componentDidUpdate(prevProps, state);
              }
            }
          // If it doesn't need to rerender, update only its props.
github airbnb / enzyme / packages / enzyme / src / ShallowWrapper.js View on Github external
function pureComponentShouldComponentUpdate(prevProps, props, prevState, state) {
  return !shallowEqual(prevProps, props) || !shallowEqual(prevState, state);
}
github airbnb / enzyme / packages / enzyme-adapter-react-16 / src / ReactSixteenAdapter.js View on Github external
wrappedComponent = function (props, ...args) {
            const shouldUpdate = memoized === sentinel || (compare
              ? !compare(prevProps, props)
              : !shallowEqual(prevProps, props)
            );
            if (shouldUpdate) {
              memoized = Component({ ...Component.defaultProps, ...props }, ...args);
              prevProps = props;
            }
            return memoized;
          };
        }

enzyme-shallow-equal

Adaptation of react-addons-shallow-compare, for independent usage

MIT
Latest version published 11 months ago

Package Health Score

87 / 100
Full package analysis

Popular enzyme-shallow-equal functions