How to use react-fast-compare - 10 common examples

To help you get started, we’ve selected a few react-fast-compare 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 fluent-org / fluent-ui / packages / fluent-ui-hooks / src / useDeepCompareEffect / useDeepCompareEffect.ts View on Github external
console.warn(
        '`useDeepCompareEffect` should not be used with no dependencies. Use React.useEffect instead.'
      )
    }

    if (deps.every(isPrimitive)) {
      // eslint-disable-next-line no-console
      console.warn(
        '`useDeepCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead.'
      )
    }
  }

  const ref = useRef(undefined)

  if (!isEqual(deps, ref.current)) {
    ref.current = deps
  }

  useEffect(effect, ref.current)
}
github FormidableLabs / victory / packages / victory-brush-container / src / brush-helpers.js View on Github external
{
          target: "parent",
          mutation: () => {
            return {
              isSelecting: true,
              domainBox,
              fullDomainBox,
              cachedBrushDomain: brushDomain,
              currentDomain,
              parentSVG,
              ...this.getResizeMutation(domainBox, activeHandles)
            };
          }
        }
      ];
    } else if (this.withinBounds({ x, y }, domainBox) && !isEqual(domain, currentDomain)) {
      // if the event occurs within a selected region start a panning event, unless the whole
      // domain is selected
      return [
        {
          target: "parent",
          mutation: () => ({
            isPanning: allowDrag,
            startX: x,
            startY: y,
            domainBox,
            fullDomainBox,
            currentDomain,
            cachedBrushDomain: brushDomain,
            parentSVG,
            ...domainBox // set x1, x2, y1, y2
          })
github js-rcon / react-console-emulator / lib / Terminal.jsx View on Github external
componentDidUpdate (prevProps) {
    // If there was a change in commands, re-validate
    if (!isEqual(prevProps.commands, this.props.commands)) this.validateCommands()
  }
github mineral-ui / mineral-ui / src / library / Table / Selectable.js View on Github external
static getDerivedStateFromProps(
    nextProps: SelectableProps,
    prevState: SelectableState
  ): $Shape | null {
    if (
      nextProps.selected !== undefined &&
      !deepEqual(nextProps.selected, prevState.selected)
    ) {
      return {
        selected: nextProps.selected
      };
    }

    return null; // no change
  }
github mineral-ui / mineral-ui / src / library / Table / TableHeaderRow.js View on Github external
shouldComponentUpdate(nextProps: TableHeaderRowProps) {
    return !deepEqual(this.props, nextProps);
  }
github jaredpalmer / formik / src / Formik.tsx View on Github external
]).then(([fieldErrors, schemaErrors, validateErrors]) => {
          const combinedErrors = deepmerge.all>(
            [fieldErrors, schemaErrors, validateErrors],
            { arrayMerge }
          );
          if (!isEqual(state.errors, combinedErrors)) {
            dispatch({ type: 'SET_ERRORS', payload: combinedErrors });
          }
          dispatch({ type: 'SET_ISVALIDATING', payload: false });
          return combinedErrors;
        });
      } else {
github rainbow-me / rainbow / src / components / asset-list / AssetList.js View on Github external
const arePropsEqual = (prev, next) =>
  prev.isEmpty === next.isEmpty &&
  prev.isWalletEthZero === next.isWalletEthZero &&
  prev.sections.length === next.sections.length &&
  isEqual(prev.sections, next.sections);
github vmware-tanzu / octant / web / react / src / components / ResourceViewer / components / Graph / index.tsx View on Github external
shouldComponentUpdate(nextProps: Props, _): boolean {
    return !isEqual(this.props.nodes, nextProps.nodes) || !isEqual(this.props.edges, nextProps.edges)
  }
github elastic / kibana / x-pack / legacy / plugins / canvas / public / components / workpad_shortcuts / workpad_shortcuts.tsx View on Github external
public shouldComponentUpdate(nextProps: Props) {
    return !isEqual(nextProps, this.props);
  }
}
github FormidableLabs / victory / packages / victory-group / src / victory-group.js View on Github external
shouldComponentUpdate(nextProps, nextState) {
    const equalProps = isEqual(this.props, nextProps);
    if (this.props.animate && !equalProps) {
      this.setAnimationState(this.props, nextProps);
    }
    this.events = Wrapper.getAllEvents(nextProps);
    return this.props.animate || !equalProps || !isEqual(this.state, nextState);
  }

react-fast-compare

Fastest deep equal comparison for React. Great for React.memo & shouldComponentUpdate. Also really fast general-purpose deep comparison.

MIT
Latest version published 11 months ago

Package Health Score

88 / 100
Full package analysis

Popular react-fast-compare functions