UNPKG

zmp-react

Version:

Build full featured iOS & Android apps using ZMP & React

12 lines (11 loc) 388 B
import { useRef } from 'react'; import { useIsomorphicLayoutEffect } from './use-isomorphic-layout-effect'; export var watchProp = function watchProp(value, callback) { var valueRef = useRef(value); useIsomorphicLayoutEffect(function () { if (value !== valueRef.current && callback) { callback(value, valueRef.current); } valueRef.current = value; }, [value]); };