useValueChanged<T, R> function

R useValueChanged <T, R>(T value, R valueChange(T oldValue, R oldResult))

Watches a value and calls a callback whenever the value changed.

useValueChanged takes a valueChange callback and calls it whenever value changed. valueChange will not be called on the first useValueChanged call.

useValueChanged can also be used to interpolate Whenever useValueChanged is called with a diffent value, calls valueChange. The value returned by useValueChanged is the latest returned value of valueChange or null.

The following example calls AnimationController.forward whenever color changes

AnimationController controller;
Color color;

useValueChanged(color, (_, __)) {
    controller.forward();
});

Implementation

R useValueChanged<T, R>(T value, R valueChange(T oldValue, R oldResult)) {
  return Hook.use(_ValueChangedHook(value, valueChange));
}