MCPcopy
hub / github.com/final-form/react-final-form / useWhenValueChanges

Function useWhenValueChanges

src/useWhenValueChanges.ts:3–15  ·  view source on GitHub ↗
(
  value: any,
  callback: () => void,
  isEqual: (a: any, b: any) => boolean = (a, b) => a === b,
)

Source from the content-addressed store, hash-verified

1import React from "react";
2
3export default function useWhenValueChanges(
4 value: any,
5 callback: () => void,
6 isEqual: (a: any, b: any) => boolean = (a, b) => a === b,
7) {
8 const previous = React.useRef(value);
9 React.useEffect(() => {
10 if (!isEqual(value, previous.current)) {
11 callback();
12 previous.current = value;
13 }
14 });
15}

Callers 1

ReactFinalFormFunction · 0.85

Calls 1

isEqualFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…